Preload all cache when fetching all refs When calling the RefDatabase.getRefs() the entire refs are loaded and present in memory: use the opportunity to cache the all set of refs into the in-memory key-value store for allowing a fast preloading of the refs cache. Change-Id: I24423089305490befe3156e80b3dbd1c7010304d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDatabase.java b/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDatabase.java index 04541bd..e40e41b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDatabase.java +++ b/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDatabase.java
@@ -140,7 +140,12 @@ @Override public List<Ref> getRefs() throws IOException { - return delegate.getRefs(); + List<Ref> allRefs = delegate.getRefs(); + for (Ref ref : allRefs) { + refsCache.computeIfAbsent( + repo.getProjectName(), ref.getName(), () -> Optional.ofNullable(ref)); + } + return allRefs; } @Override