summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Milanesio <luca.milanesio@gmail.com>2022-10-28 21:29:51 +0100
committerLuca Milanesio <luca.milanesio@gmail.com>2022-10-28 21:29:51 +0100
commitd69730112abc4132007a70c956ad1fce2e5a5ad6 (patch)
tree53361f303779d4fb959b02cf22d9e519932069fd
parent353a005f8e6abf047ad16b64978636d225861d81 (diff)
parentdb624fd4d296bde8b62dc4ca8d9fd2b5dfcd99ab (diff)
Merge branch 'stable-3.1' into stable-3.2
* stable-3.1: Cache repository locations in LocalDiskRepositoryManager Release-Notes: skip Change-Id: I5443e5174552f2a8369f5d97162b9cb24cd2ae26
-rw-r--r--java/com/google/gerrit/server/git/LocalDiskRepositoryManager.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/java/com/google/gerrit/server/git/LocalDiskRepositoryManager.java b/java/com/google/gerrit/server/git/LocalDiskRepositoryManager.java
index d42ed2578a..6ccb73c6ce 100644
--- a/java/com/google/gerrit/server/git/LocalDiskRepositoryManager.java
+++ b/java/com/google/gerrit/server/git/LocalDiskRepositoryManager.java
@@ -33,8 +33,10 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
import java.util.EnumSet;
+import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
@@ -108,6 +110,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
}
private final Path basePath;
+ private final Map<Project.NameKey, FileKey> fileKeyByProject = new ConcurrentHashMap<>();
@Inject
LocalDiskRepositoryManager(SitePaths site, @GerritServerConfig Config cfg) {
@@ -129,17 +132,23 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
@Override
public Repository openRepository(Project.NameKey name) throws RepositoryNotFoundException {
- return openRepository(getBasePath(name), name);
- }
+ FileKey cachedLocation = fileKeyByProject.get(name);
+ if (cachedLocation != null) {
+ try {
+ return RepositoryCache.open(cachedLocation);
+ } catch (IOException e) {
+ fileKeyByProject.remove(name, cachedLocation);
+ }
+ }
- private Repository openRepository(Path path, Project.NameKey name)
- throws RepositoryNotFoundException {
if (isUnreasonableName(name)) {
throw new RepositoryNotFoundException("Invalid name: " + name);
}
- FileKey loc = FileKey.lenient(path.resolve(name.get()).toFile(), FS.DETECTED);
+ FileKey location = FileKey.lenient(getBasePath(name).resolve(name.get()).toFile(), FS.DETECTED);
try {
- return RepositoryCache.open(loc);
+ Repository repo = RepositoryCache.open(location);
+ fileKeyByProject.put(name, location);
+ return repo;
} catch (IOException e) {
throw new RepositoryNotFoundException("Cannot open repository " + name, e);
}