Skip to content

Commit

Permalink
Added querycount to getWithExtraInfo (#367)
Browse files Browse the repository at this point in the history
* Added querycount to getWithExtraInfo

* Created a static variable for queryCount

* Added a comment to re-run the build
  • Loading branch information
rakhiagr authored Feb 28, 2024
1 parent 4c3c06c commit 0ebf2ce
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public class EbeanLocalDAO<ASPECT_UNION extends UnionTemplate, URN extends Urn>

protected final EbeanServer _server;
protected final Class<URN> _urnClass;
private int _queryKeysCount = 0; // 0 means no pagination on keys

private final static int DEFAULT_BATCH_SIZE = 50;
private int _queryKeysCount = DEFAULT_BATCH_SIZE;
private IEbeanLocalAccess<URN> _localAccess;
private UrnPathExtractor<URN> _urnPathExtractor;
private SchemaConfig _schemaConfig = SchemaConfig.OLD_SCHEMA_ONLY;
Expand Down Expand Up @@ -899,9 +901,12 @@ protected <ASPECT extends RecordTemplate> void applyTimeBasedRetention(@Nonnull
if (keys.isEmpty()) {
return Collections.emptyMap();
}

final List<EbeanMetadataAspect> records = batchGet(keys, keys.size());

final List<EbeanMetadataAspect> records;
if (_queryKeysCount == 0) {
records = batchGet(keys, keys.size());
} else {
records = batchGet(keys, _queryKeysCount);
}
final Map<AspectKey<URN, ? extends RecordTemplate>, AspectWithExtraInfo<? extends RecordTemplate>> result =
new HashMap<>();
keys.forEach(key -> records.stream()
Expand Down Expand Up @@ -941,13 +946,18 @@ public boolean exists(@Nonnull URN urn) {
}

/**
* Sets the max keys allowed for each single query.
* Sets the max keys allowed for each single query, not allowed more than the default batch size.
*/
public void setQueryKeysCount(int keysCount) {
if (keysCount < 0) {
throw new IllegalArgumentException("Query keys count must be non-negative: " + keysCount);
} else if (keysCount > DEFAULT_BATCH_SIZE) {
log.warn("Setting query keys count greater than " + DEFAULT_BATCH_SIZE
+ " may cause performance issues. Defaulting to " + DEFAULT_BATCH_SIZE + ".");
_queryKeysCount = DEFAULT_BATCH_SIZE;
} else {
_queryKeysCount = keysCount;
}
_queryKeysCount = keysCount;
}

/**
Expand Down

0 comments on commit 0ebf2ce

Please sign in to comment.