From 43747d57584c329c9cd5650ef3a7ba1aa2602f40 Mon Sep 17 00:00:00 2001 From: rjawesome Date: Fri, 20 Sep 2024 17:05:52 -0700 Subject: [PATCH] handle duplicate queries --- src/batch_edge_query.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/batch_edge_query.ts b/src/batch_edge_query.ts index b4576545..e8d16213 100644 --- a/src/batch_edge_query.ts +++ b/src/batch_edge_query.ts @@ -68,9 +68,10 @@ export default class BatchEdgeQueryHandler { }); const queriesByHash = Object.fromEntries(queries.map((query) => [query.hash, query])); + const queryCount = Object.keys(queriesByHash).length; // some duplicates may have been removed const qEdge = APIEdges[0].reasoner_edge; - const message = `${queries.length} planned queries for edge ${qEdge.id}`; + const message = `${queryCount} planned queries for edge ${qEdge.id}`; debug(message); this.logs.push(new LogEntry('INFO', null, message).getLog()); let finishedCount = 0; @@ -106,7 +107,7 @@ export default class BatchEdgeQueryHandler { } finishedCount += 1; - if (finishedCount >= queries.length) { + if (finishedCount >= queryCount) { debug(`Total number of records returned for qEdge ${qEdge.id} is ${completedRecords.length}`); resolve(completedRecords); global.workerSide.off('message', listener); @@ -124,7 +125,7 @@ export default class BatchEdgeQueryHandler { threadId, type: 'subqueryRequest', value: { - queries: queries.map((query) => query.freeze()), + queries: Object.values(queriesByHash).map((query) => query.freeze()), // queriesByHash prevents duplicates options: this.options, }, } satisfies ThreadMessage);