commit | 6ee2c77081fb4a347c7bd73a599615b417c0e305 | [log] [tgz] |
---|---|---|
author | Luca Milanesio <luca.milanesio@gmail.com> | Thu Jul 21 19:53:12 2022 +0100 |
committer | Luca Milanesio <luca.milanesio@gmail.com> | Thu Jul 21 19:59:03 2022 +0100 |
tree | 6bd00bee8696f217650e557c0d16c841aa22e0d2 | |
parent | 74f4261a5d3270786a790343940e1cef9e1379ab [diff] |
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