Skip to content

Commit

Permalink
Fix for leaking mongodb cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 committed Jan 18, 2023
1 parent eeba1a6 commit a1ff525
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ public BasicPolyList read(String poly, Set<String> ids) {

final BasicPolyList dbPolys = new BasicPolyList();
Bson query = Filters.in(_ID, ids);
collection(poly).find(query).iterator().forEachRemaining(document -> {
BasicPoly polyData = toPoly(document);
dbPolys.add(polyData);
});
try (MongoCursor<Document> cursor = collection(poly).find(query).iterator()) {
cursor.forEachRemaining(document -> {
BasicPoly polyData = toPoly(document);
dbPolys.add(polyData);
});
}
if (cache.isPresent()) {
Cache cacheInstance = cache.get();
for (BasicPoly polyData : dbPolys.list()) {
Expand Down Expand Up @@ -444,8 +446,10 @@ private void recalculateIndex(String poly) {
indexData.put("poly", poly);
indexes.add(indexData);
}
indexCollection(poly).drop();
indexCollection(poly).insertMany(indexes.stream().map(this::toDocument).collect(Collectors.toList()));
if (!indexes.isEmpty()) {
indexCollection(poly).drop();
indexCollection(poly).insertMany(indexes.stream().map(this::toDocument).collect(Collectors.toList()));
}
}
}

Expand Down

0 comments on commit a1ff525

Please sign in to comment.