Skip to content

Commit

Permalink
handle duplicate queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Sep 21, 2024
1 parent bf42f1c commit 43747d5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/batch_edge_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 43747d5

Please sign in to comment.