ChangeUtil: Reload changes in findChanges
Don't depend on values from the secondary index; ensure the change in the control is a fresh read from the database. This means, for example, we use the latest status to check visibility of drafts, rather than trusting the secondary index. Change-Id: I004ea0bb8d587b55e4f552848b2aef14c52d0638
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.server;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.google.gerrit.common.TimeUtil;
|
import com.google.gerrit.common.TimeUtil;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -444,15 +445,20 @@ public class ChangeUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the index to search for changes, but don't return any stored fields,
|
||||||
|
// to force rereading in case the index is stale.
|
||||||
|
InternalChangeQuery query = queryProvider.get()
|
||||||
|
.setRequestedFields(ImmutableSet.<String> of());
|
||||||
|
|
||||||
// Try isolated changeId
|
// Try isolated changeId
|
||||||
if (!id.contains("~")) {
|
if (!id.contains("~")) {
|
||||||
return asChangeControls(queryProvider.get().byKeyPrefix(id));
|
return asChangeControls(query.byKeyPrefix(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try change triplet
|
// Try change triplet
|
||||||
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id);
|
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id);
|
||||||
if (triplet.isPresent()) {
|
if (triplet.isPresent()) {
|
||||||
return asChangeControls(queryProvider.get().byBranchKey(
|
return asChangeControls(query.byBranchKey(
|
||||||
triplet.get().branch(),
|
triplet.get().branch(),
|
||||||
triplet.get().id()));
|
triplet.get().id()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ public class InternalChangeQuery {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InternalChangeQuery setRequestedFields(Set<String> fields) {
|
||||||
|
qp.setRequestedFields(fields);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ChangeData> byKey(Change.Key key) throws OrmException {
|
public List<ChangeData> byKey(Change.Key key) throws OrmException {
|
||||||
return byKeyPrefix(key.get());
|
return byKeyPrefix(key.get());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user