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:
Dave Borowitz
2015-10-28 12:08:46 -04:00
parent 0be8b71c5c
commit f0f2533e3e
2 changed files with 13 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
import com.google.gerrit.common.TimeUtil;
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
if (!id.contains("~")) {
return asChangeControls(queryProvider.get().byKeyPrefix(id));
return asChangeControls(query.byKeyPrefix(id));
}
// Try change triplet
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id);
if (triplet.isPresent()) {
return asChangeControls(queryProvider.get().byBranchKey(
return asChangeControls(query.byBranchKey(
triplet.get().branch(),
triplet.get().id()));
}