[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:
Wyatt Johnson
2019-02-06 17:53:34 +00:00
committed by GitHub
parent 7e8ef2189d
commit 9b0e6ed53b
26 changed files with 397 additions and 126 deletions
@@ -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");
}
+4
View File
@@ -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);