mirror of
https://github.com/wassname/talk.git
synced 2026-07-04 16:15:37 +08:00
fix: include tenantID in query operation to improve index use (#2596)
This commit is contained in:
@@ -140,7 +140,7 @@ export async function createCommentActionIndexes(mongo: Db) {
|
||||
// UNIQUE { id }
|
||||
await createIndex({ tenantID: 1, id: 1 }, { unique: true });
|
||||
|
||||
// { actionType, commentID }
|
||||
// { actionType, commentID, userID }
|
||||
await createIndex(
|
||||
{ tenantID: 1, actionType: 1, commentID: 1, userID: 1 },
|
||||
{ background: true }
|
||||
@@ -232,7 +232,7 @@ export async function createAction(
|
||||
input: CreateActionInput,
|
||||
now = new Date()
|
||||
): Promise<CreateActionResultObject> {
|
||||
const { metadata, additionalDetails, ...filter } = input;
|
||||
const { metadata, additionalDetails, ...rest } = input;
|
||||
|
||||
// Create a new ID for the action.
|
||||
const id = uuid.v4();
|
||||
@@ -245,6 +245,12 @@ export async function createAction(
|
||||
createdAt: now,
|
||||
};
|
||||
|
||||
// Extract the filter parameters.
|
||||
const filter: FilterQuery<CommentAction> = {
|
||||
tenantID,
|
||||
...rest,
|
||||
};
|
||||
|
||||
// Merge the defaults with the input.
|
||||
const action: Readonly<CommentAction> = {
|
||||
...defaults,
|
||||
|
||||
Reference in New Issue
Block a user