Merge branch 'stable-2.11' into stable-2.12
* stable-2.11: SiteIndexer: Always scan changes from repo/db Make JdbcUtil#port() public Allow to use GWTORM Key classes in plugins Change-Id: I90edcb6a930e9125e1a56d19d1765d502eaf25ab
This commit is contained in:
@@ -99,7 +99,7 @@ public final class Change {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Column(id = 1)
|
@Column(id = 1)
|
||||||
protected int id;
|
public int id;
|
||||||
|
|
||||||
protected Id() {
|
protected Id() {
|
||||||
}
|
}
|
||||||
|
@@ -23,9 +23,9 @@ public class LabelId extends StringKey<com.google.gwtorm.client.Key<?>> {
|
|||||||
public static final LabelId SUBMIT = new LabelId("SUBM");
|
public static final LabelId SUBMIT = new LabelId("SUBM");
|
||||||
|
|
||||||
@Column(id = 1)
|
@Column(id = 1)
|
||||||
protected String id;
|
public String id;
|
||||||
|
|
||||||
protected LabelId() {
|
public LabelId() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelId(final String n) {
|
public LabelId(final String n) {
|
||||||
|
@@ -77,12 +77,12 @@ public final class PatchSet {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Column(id = 1)
|
@Column(id = 1)
|
||||||
protected Change.Id changeId;
|
public Change.Id changeId;
|
||||||
|
|
||||||
@Column(id = 2)
|
@Column(id = 2)
|
||||||
protected int patchSetId;
|
public int patchSetId;
|
||||||
|
|
||||||
protected Id() {
|
public Id() {
|
||||||
changeId = new Change.Id();
|
changeId = new Change.Id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.cache.CacheModule;
|
import com.google.gerrit.server.cache.CacheModule;
|
||||||
import com.google.gerrit.server.util.ManualRequestContext;
|
import com.google.gerrit.server.util.ManualRequestContext;
|
||||||
import com.google.gerrit.server.util.OneOffRequestContext;
|
import com.google.gerrit.server.util.OneOffRequestContext;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -37,6 +38,7 @@ import org.eclipse.jgit.lib.Repository;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -97,25 +99,29 @@ public class ScanningChangeCacheImpl implements ChangeCache {
|
|||||||
public List<Change> load(Project.NameKey key) throws Exception {
|
public List<Change> load(Project.NameKey key) throws Exception {
|
||||||
try (Repository repo = repoManager.openRepository(key);
|
try (Repository repo = repoManager.openRepository(key);
|
||||||
ManualRequestContext ctx = requestContext.open()) {
|
ManualRequestContext ctx = requestContext.open()) {
|
||||||
ReviewDb db = ctx.getReviewDbProvider().get();
|
return scan(repo, ctx.getReviewDbProvider().get());
|
||||||
Map<String, Ref> refs =
|
|
||||||
repo.getRefDatabase().getRefs(RefNames.REFS_CHANGES);
|
|
||||||
Set<Change.Id> ids = new LinkedHashSet<>();
|
|
||||||
for (Ref r : refs.values()) {
|
|
||||||
Change.Id id = Change.Id.fromRef(r.getName());
|
|
||||||
if (id != null) {
|
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<Change> changes = new ArrayList<>(ids.size());
|
|
||||||
// A batch size of N may overload get(Iterable), so use something smaller,
|
|
||||||
// but still >1.
|
|
||||||
for (List<Change.Id> batch : Iterables.partition(ids, 30)) {
|
|
||||||
Iterables.addAll(changes, db.changes().get(batch));
|
|
||||||
}
|
|
||||||
return changes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Change> scan(Repository repo, ReviewDb db)
|
||||||
|
throws OrmException, IOException {
|
||||||
|
Map<String, Ref> refs =
|
||||||
|
repo.getRefDatabase().getRefs(RefNames.REFS_CHANGES);
|
||||||
|
Set<Change.Id> ids = new LinkedHashSet<>();
|
||||||
|
for (Ref r : refs.values()) {
|
||||||
|
Change.Id id = Change.Id.fromRef(r.getName());
|
||||||
|
if (id != null) {
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Change> changes = new ArrayList<>(ids.size());
|
||||||
|
// A batch size of N may overload get(Iterable), so use something smaller,
|
||||||
|
// but still >1.
|
||||||
|
for (List<Change.Id> batch : Iterables.partition(ids, 30)) {
|
||||||
|
Iterables.addAll(changes, db.changes().get(batch));
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,11 +33,11 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
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.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.MergeUtil;
|
import com.google.gerrit.server.git.MergeUtil;
|
||||||
import com.google.gerrit.server.git.MultiProgressMonitor;
|
import com.google.gerrit.server.git.MultiProgressMonitor;
|
||||||
import com.google.gerrit.server.git.MultiProgressMonitor.Task;
|
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.patch.PatchListLoader;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
@@ -112,7 +112,6 @@ public class SiteIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final SchemaFactory<ReviewDb> schemaFactory;
|
private final SchemaFactory<ReviewDb> schemaFactory;
|
||||||
private final ChangeCache changeCache;
|
|
||||||
private final ChangeData.Factory changeDataFactory;
|
private final ChangeData.Factory changeDataFactory;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final ListeningExecutorService executor;
|
private final ListeningExecutorService executor;
|
||||||
@@ -126,14 +125,12 @@ public class SiteIndexer {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SiteIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
SiteIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
||||||
ChangeCache changeCache,
|
|
||||||
ChangeData.Factory changeDataFactory,
|
ChangeData.Factory changeDataFactory,
|
||||||
GitRepositoryManager repoManager,
|
GitRepositoryManager repoManager,
|
||||||
@IndexExecutor(BATCH) ListeningExecutorService executor,
|
@IndexExecutor(BATCH) ListeningExecutorService executor,
|
||||||
ChangeIndexer.Factory indexerFactory,
|
ChangeIndexer.Factory indexerFactory,
|
||||||
@GerritServerConfig Config config) {
|
@GerritServerConfig Config config) {
|
||||||
this.schemaFactory = schemaFactory;
|
this.schemaFactory = schemaFactory;
|
||||||
this.changeCache = changeCache;
|
|
||||||
this.changeDataFactory = changeDataFactory;
|
this.changeDataFactory = changeDataFactory;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
@@ -241,7 +238,7 @@ public class SiteIndexer {
|
|||||||
try (Repository repo = repoManager.openRepository(project);
|
try (Repository repo = repoManager.openRepository(project);
|
||||||
ReviewDb db = schemaFactory.open()) {
|
ReviewDb db = schemaFactory.open()) {
|
||||||
Map<String, Ref> refs = repo.getRefDatabase().getRefs(ALL);
|
Map<String, Ref> 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());
|
Ref r = refs.get(c.currentPatchSetId().toRefName());
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
byId.put(r.getObjectId(), changeDataFactory.create(db, c));
|
byId.put(r.getObjectId(), changeDataFactory.create(db, c));
|
||||||
|
@@ -26,7 +26,7 @@ public class JdbcUtil {
|
|||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String port(String port) {
|
public static String port(String port) {
|
||||||
if (port != null && !port.isEmpty()) {
|
if (port != null && !port.isEmpty()) {
|
||||||
return ":" + port;
|
return ":" + port;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user