[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
+15 -2
View File
@@ -11,7 +11,10 @@ import {
GQLCOMMENT_FLAG_REASON,
GQLCOMMENT_FLAG_REPORTED_REASON,
} from "talk-server/graph/tenant/schema/__generated__/types";
import { FilterQuery } from "talk-server/models/query";
import {
createIndexFactory,
FilterQuery,
} from "talk-server/models/helpers/query";
import { TenantResource } from "talk-server/models/tenant";
function collection(db: Db) {
@@ -103,6 +106,16 @@ export interface CommentAction extends TenantResource {
metadata?: Record<string, any>;
}
export async function createCommentActionIndexes(mongo: Db) {
const createIndex = createIndexFactory(collection(mongo));
// UNIQUE { id }
await createIndex({ tenantID: 1, id: 1 }, { unique: true });
// { actionType, commentID }
await createIndex({ tenantID: 1, actionType: 1, commentID: 1, userID: 1 });
}
const ActionSchema = [
// Flags
{
@@ -245,9 +258,9 @@ export async function retrieveUserAction(
) {
return collection(mongo).findOne({
tenantID,
actionType,
commentID,
userID,
actionType,
});
}
@@ -8,8 +8,11 @@ import {
ConnectionInput,
getPageInfo,
nodesToEdges,
} from "talk-server/models/connection";
import Query from "talk-server/models/query";
} from "talk-server/models/helpers/connection";
import Query, {
createConnectionOrderVariants,
createIndexFactory,
} from "talk-server/models/helpers/query";
import { TenantResource } from "talk-server/models/tenant";
function collection(db: Db) {
@@ -18,6 +21,22 @@ function collection(db: Db) {
);
}
export async function createCommentModerationActionIndexes(mongo: Db) {
const createIndex = createIndexFactory(collection(mongo));
// UNIQUE { id }
await createIndex({ tenantID: 1, id: 1 }, { unique: true });
const createVariants = createConnectionOrderVariants<
Readonly<CommentModerationAction>
>([{ createdAt: -1 }]);
// { moderatorID, ...connectionParams }
await createVariants(createIndex, {
moderatorID: 1,
});
}
/**
* CommentModerationAction stores information around a moderation action that
* was created for a given Comment Revision.