Skip to content

Commit

Permalink
Simplify options timeout setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Apr 5, 2024
1 parent 3807b89 commit 6cdf19a
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ public BsonValue decrypt(final BsonBinary value) {

@Override
public DeleteResult deleteKey(final BsonBinary id) {
return collectionWithTimeout(collection, startTimeout()).deleteOne(Filters.eq("_id", id));
return collectionWithOptionsTimeout().deleteOne(Filters.eq("_id", id));
}

@Override
public BsonDocument getKey(final BsonBinary id) {
return collectionWithTimeout(collection, startTimeout()).find(Filters.eq("_id", id)).first();
return collectionWithOptionsTimeout().find(Filters.eq("_id", id)).first();
}

@Override
public FindIterable<BsonDocument> getKeys() {
return collectionWithTimeout(collection, startTimeout()).find();
return collectionWithOptionsTimeout().find();
}

@Override
Expand Down Expand Up @@ -283,4 +283,9 @@ public void close() {
private Timeout startTimeout() {
return TimeoutContext.calculateTimeout(options.getTimeout(MILLISECONDS));
}

private MongoCollection<BsonDocument> collectionWithOptionsTimeout() {
Long timeout = options.getTimeout(MILLISECONDS);
return timeout != null ? collection.withTimeout(timeout, MILLISECONDS) : collection;
}
}

0 comments on commit 6cdf19a

Please sign in to comment.