Skip to content

Commit

Permalink
fix: use proper index when (re)calculating the additional balance
Browse files Browse the repository at this point in the history
  • Loading branch information
koresar committed May 14, 2024
1 parent e677d0f commit 6900887
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export class Book<U extends ITransaction = ITransaction, J extends IJournal = IJ
if (balanceSnapshot) {
// Use cached balance
parsedQuery._id = { $gt: balanceSnapshot.transaction };
// And make sure to use the appropriate (default "_id_") index for the additional balance
options.hint = { _id: 1 };
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/IOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ClientSession } from "mongoose";
import { ReadPreferenceLike } from "mongodb";
import type { ClientSession } from "mongoose";
import type { ReadPreferenceLike, Hint } from "mongodb";

// aggregate of mongoose expects Record<string, unknown> type
export type IOptions = {
session?: ClientSession;
readPreference?: ReadPreferenceLike;
hint?: Hint;
};

0 comments on commit 6900887

Please sign in to comment.