Skip to content

Commit

Permalink
filtering out deleted documents from the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tnaum-ms committed Dec 4, 2024
1 parent 305e49d commit f8ccbed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/mongoClusters/MongoClusterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,23 @@ export class MongoClustersSession {
if (ObjectId.isValid(id)) {
parsedId = new ObjectId(id);
} else {
return false;
parsedId = id;
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return doc._id.equals(parsedId);

/**
* deep equality for _id is tricky as we'd have to consider embedded objects,
* arrays, etc. For now, we'll just stringify the _id and compare the strings.
* The reasoning here is that this operation is used during interactive work
* and were not expecting to delete a large number of documents at once.
* Hence, the performance impact of this approach is negligible, and it's more
* about simplicity here.
*/

const docIdStr = EJSON.stringify(doc._id, { relaxed: false }, 0);
const parsedIdStr = EJSON.stringify(parsedId, { relaxed: false }, 0);

return docIdStr === parsedIdStr;
});
});
}
Expand Down

0 comments on commit f8ccbed

Please sign in to comment.