From 29297bba6310c0eded6b674385299d777c9ca9d8 Mon Sep 17 00:00:00 2001 From: koresar Date: Wed, 15 May 2024 21:30:57 +1000 Subject: [PATCH] fix: use "_id" index hint for balance re-calc only of that ID was a recent one --- src/Book.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Book.ts b/src/Book.ts index 8d1a5e4..f34a81b 100644 --- a/src/Book.ts +++ b/src/Book.ts @@ -109,7 +109,13 @@ export class Book Date.now()) { + // last transaction for this balance was just recently, then let's use the "_id" index as it will likely be faster than any other. + partialBalanceOptions.hint = { _id: 1 }; + } + } const result = (await transactionModel.collection.aggregate([match, GROUP], partialBalanceOptions).toArray())[0]; let balance = 0;