diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java index d2906d39e3..4154093759 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java @@ -99,7 +99,7 @@ public final class Change { private static final long serialVersionUID = 1L; @Column(id = 1) - protected int id; + public int id; protected Id() { } diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/LabelId.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/LabelId.java index 9a159664be..f2af5fa6cb 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/LabelId.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/LabelId.java @@ -23,9 +23,9 @@ public class LabelId extends StringKey> { public static final LabelId SUBMIT = new LabelId("SUBM"); @Column(id = 1) - protected String id; + public String id; - protected LabelId() { + public LabelId() { } public LabelId(final String n) { diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java index ae1b75b3da..7f4fd12025 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java @@ -77,12 +77,12 @@ public final class PatchSet { private static final long serialVersionUID = 1L; @Column(id = 1) - protected Change.Id changeId; + public Change.Id changeId; @Column(id = 2) - protected int patchSetId; + public int patchSetId; - protected Id() { + public Id() { changeId = new Change.Id(); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ScanningChangeCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ScanningChangeCacheImpl.java index 19e23b74e9..faf37767d9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ScanningChangeCacheImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ScanningChangeCacheImpl.java @@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.cache.CacheModule; import com.google.gerrit.server.util.ManualRequestContext; import com.google.gerrit.server.util.OneOffRequestContext; +import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Module; import com.google.inject.Singleton; @@ -37,6 +38,7 @@ import org.eclipse.jgit.lib.Repository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -97,25 +99,29 @@ public class ScanningChangeCacheImpl implements ChangeCache { public List load(Project.NameKey key) throws Exception { try (Repository repo = repoManager.openRepository(key); ManualRequestContext ctx = requestContext.open()) { - ReviewDb db = ctx.getReviewDbProvider().get(); - Map refs = - repo.getRefDatabase().getRefs(RefNames.REFS_CHANGES); - Set ids = new LinkedHashSet<>(); - for (Ref r : refs.values()) { - Change.Id id = Change.Id.fromRef(r.getName()); - if (id != null) { - ids.add(id); - } - } - List changes = new ArrayList<>(ids.size()); - // A batch size of N may overload get(Iterable), so use something smaller, - // but still >1. - for (List batch : Iterables.partition(ids, 30)) { - Iterables.addAll(changes, db.changes().get(batch)); - } - return changes; + return scan(repo, ctx.getReviewDbProvider().get()); } } } + + public static List scan(Repository repo, ReviewDb db) + throws OrmException, IOException { + Map refs = + repo.getRefDatabase().getRefs(RefNames.REFS_CHANGES); + Set ids = new LinkedHashSet<>(); + for (Ref r : refs.values()) { + Change.Id id = Change.Id.fromRef(r.getName()); + if (id != null) { + ids.add(id); + } + } + List changes = new ArrayList<>(ids.size()); + // A batch size of N may overload get(Iterable), so use something smaller, + // but still >1. + for (List batch : Iterables.partition(ids, 30)) { + Iterables.addAll(changes, db.changes().get(batch)); + } + return changes; + } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/index/SiteIndexer.java b/gerrit-server/src/main/java/com/google/gerrit/server/index/SiteIndexer.java index 1bc6b0521f..53af8ada00 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/index/SiteIndexer.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/index/SiteIndexer.java @@ -33,11 +33,11 @@ import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.config.GerritServerConfig; -import com.google.gerrit.server.git.ChangeCache; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.MergeUtil; import com.google.gerrit.server.git.MultiProgressMonitor; import com.google.gerrit.server.git.MultiProgressMonitor.Task; +import com.google.gerrit.server.git.ScanningChangeCacheImpl; import com.google.gerrit.server.patch.PatchListLoader; import com.google.gerrit.server.query.change.ChangeData; import com.google.gwtorm.server.SchemaFactory; @@ -112,7 +112,6 @@ public class SiteIndexer { } private final SchemaFactory schemaFactory; - private final ChangeCache changeCache; private final ChangeData.Factory changeDataFactory; private final GitRepositoryManager repoManager; private final ListeningExecutorService executor; @@ -126,14 +125,12 @@ public class SiteIndexer { @Inject SiteIndexer(SchemaFactory schemaFactory, - ChangeCache changeCache, ChangeData.Factory changeDataFactory, GitRepositoryManager repoManager, @IndexExecutor(BATCH) ListeningExecutorService executor, ChangeIndexer.Factory indexerFactory, @GerritServerConfig Config config) { this.schemaFactory = schemaFactory; - this.changeCache = changeCache; this.changeDataFactory = changeDataFactory; this.repoManager = repoManager; this.executor = executor; @@ -241,7 +238,7 @@ public class SiteIndexer { try (Repository repo = repoManager.openRepository(project); ReviewDb db = schemaFactory.open()) { Map refs = repo.getRefDatabase().getRefs(ALL); - for (Change c : changeCache.get(project)) { + for (Change c : ScanningChangeCacheImpl.scan(repo, db)) { Ref r = refs.get(c.currentPatchSetId().toRefName()); if (r != null) { byId.put(r.getObjectId(), changeDataFactory.create(db, c)); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/JdbcUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/JdbcUtil.java index 90ca43d8c3..2624923a5c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/JdbcUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/JdbcUtil.java @@ -26,7 +26,7 @@ public class JdbcUtil { return hostname; } - static String port(String port) { + public static String port(String port) { if (port != null && !port.isEmpty()) { return ":" + port; }