Get all projects from ProjectCache instead of GitRepositoryManager

SubmoduleSectionParser was using GitRepositoryManager list method to get
all the projects. According to the inline comment in the list method
implementation in LocalDiskRepositoryManager, this method should only be
called when the cache was flushed by the administrator.

Every time the SubmoduleSectionParser was parsing the sections to find
submodule subscription, it was scanning the file system to find all the
projects.

Change-Id: I745e780e200cf5f4a245c3a08feb18fe7be150a7
This commit is contained in:
Hugo Arès
2015-04-17 09:54:30 -04:00
parent 723d26d39f
commit cf2415ad0d
2 changed files with 20 additions and 23 deletions

View File

@@ -17,7 +17,7 @@ package com.google.gerrit.server.util;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -53,17 +53,17 @@ public class SubmoduleSectionParser {
Branch.NameKey superProjectBranch);
}
private final GitRepositoryManager repoManager;
private final ProjectCache projectCache;
private final BlobBasedConfig bbc;
private final String thisServer;
private final Branch.NameKey superProjectBranch;
@Inject
public SubmoduleSectionParser(GitRepositoryManager repoManager,
public SubmoduleSectionParser(ProjectCache projectCache,
@Assisted BlobBasedConfig bbc,
@Assisted String thisServer,
@Assisted Branch.NameKey superProjectBranch) {
this.repoManager = repoManager;
this.projectCache = projectCache;
this.bbc = bbc;
this.thisServer = thisServer;
this.superProjectBranch = superProjectBranch;
@@ -116,12 +116,10 @@ public class SubmoduleSectionParser {
projectName = projectName.substring(0, //
projectName.length() - Constants.DOT_GIT_EXT.length());
}
if (repoManager.list().contains(new Project.NameKey(projectName))) {
return new SubmoduleSubscription(
superProjectBranch,
new Branch.NameKey(new Project.NameKey(projectName), branch),
path);
Project.NameKey projectKey = new Project.NameKey(projectName);
if (projectCache.get(projectKey) != null) {
return new SubmoduleSubscription(superProjectBranch,
new Branch.NameKey(projectKey, branch), path);
}
}
}

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.util;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
@@ -23,7 +24,8 @@ import static org.junit.Assert.assertEquals;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.BlobBasedConfig;
@@ -33,16 +35,14 @@ import org.junit.Test;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
private static final String THIS_SERVER = "localhost";
private GitRepositoryManager repoManager;
private ProjectCache projectCache;
private BlobBasedConfig bbc;
@Override
@@ -50,16 +50,16 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
public void setUp() throws Exception {
super.setUp();
repoManager = createStrictMock(GitRepositoryManager.class);
projectCache = createStrictMock(ProjectCache.class);
bbc = createStrictMock(BlobBasedConfig.class);
}
private void doReplay() {
replay(repoManager, bbc);
replay(projectCache, bbc);
}
private void doVerify() {
verify(repoManager, bbc);
verify(projectCache, bbc);
}
@Test
@@ -214,13 +214,12 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
projectNameCandidate.length() - Constants.DOT_GIT_EXT.length());
}
if (projectNameCandidate.equals(reposToBeFound.get(id))) {
expect(repoManager.list()).andReturn(
new TreeSet<>(Collections.singletonList(
new Project.NameKey(projectNameCandidate))));
expect(projectCache.get(new Project.NameKey(projectNameCandidate)))
.andReturn(createNiceMock(ProjectState.class));
break;
} else {
expect(repoManager.list()).andReturn(
new TreeSet<>(Collections.<Project.NameKey> emptyList()));
expect(projectCache.get(new Project.NameKey(projectNameCandidate)))
.andReturn(null);
}
}
}
@@ -229,7 +228,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
doReplay();
final SubmoduleSectionParser ssp =
new SubmoduleSectionParser(repoManager, bbc, THIS_SERVER,
new SubmoduleSectionParser(projectCache, bbc, THIS_SERVER,
superProjectBranch);
List<SubmoduleSubscription> returnedSubscriptions = ssp.parseAllSections();