mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
[next] MongoDB Indexes (#2142)
* feat: added mongo indexing support * fix: fixed typescript issue * chore: better types * fix: revert debug stuff * fix: addressed ts error * feat: added config option to disable auto-indexing * chore: reordered imports * refactor: cleaned up some filepaths
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { Db } from "mongodb";
|
||||
|
||||
import logger from "talk-server/logger";
|
||||
import { createCommentActionIndexes } from "talk-server/models/action/comment";
|
||||
import { createCommentModerationActionIndexes } from "talk-server/models/action/moderation/comment";
|
||||
import { createCommentIndexes } from "talk-server/models/comment";
|
||||
import {
|
||||
createStoryCountIndexes,
|
||||
createStoryIndexes,
|
||||
} from "talk-server/models/story";
|
||||
import { createTenantIndexes } from "talk-server/models/tenant";
|
||||
import { createUserIndexes } from "talk-server/models/user";
|
||||
|
||||
type IndexCreationFunction = (mongo: Db) => Promise<void>;
|
||||
|
||||
const indexes: Array<[string, IndexCreationFunction]> = [
|
||||
["users", createUserIndexes],
|
||||
["tenants", createTenantIndexes],
|
||||
["comments", createCommentIndexes],
|
||||
["stories", createStoryIndexes],
|
||||
["stories", createStoryCountIndexes],
|
||||
["commentActions", createCommentActionIndexes],
|
||||
["commentModerationActions", createCommentModerationActionIndexes],
|
||||
];
|
||||
|
||||
/**
|
||||
* ensureIndexes will ensure that all indexes have been created.
|
||||
*
|
||||
* @param mongo a MongoDB Database Connection
|
||||
*/
|
||||
export async function ensureIndexes(mongo: Db) {
|
||||
logger.debug(
|
||||
{ indexGroupCount: indexes.length },
|
||||
"now ensuring indexes are created"
|
||||
);
|
||||
|
||||
// For each of the index functions, call it.
|
||||
for (const [indexGroup, indexFunction] of indexes) {
|
||||
logger.debug({ indexGroup }, "ensuring indexes are created");
|
||||
await indexFunction(mongo);
|
||||
logger.debug({ indexGroup }, "indexes have been created");
|
||||
}
|
||||
|
||||
logger.debug("all indexes have been created");
|
||||
}
|
||||
@@ -50,6 +50,10 @@ export async function install(
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: (wyattjoh) perform any pending migrations.
|
||||
|
||||
// TODO: (wyattjoh) setup database indexes.
|
||||
|
||||
// Create the Tenant.
|
||||
const tenant = await createTenant(mongo, input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user