use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class StalenessChecker method check.
/**
* Returns a {@link StalenessCheckResult} with structured information about staleness of the
* provided {@link com.google.gerrit.entities.Project.NameKey}.
*/
public StalenessCheckResult check(Project.NameKey project) {
ProjectData projectData = projectCache.get(project).orElseThrow(illegalState(project)).toProjectData();
ProjectIndex i = indexes.getSearchIndex();
if (i == null) {
return StalenessCheckResult.notStale();
}
Optional<FieldBundle> result = i.getRaw(project, QueryOptions.create(indexConfig, 0, 1, FIELDS));
if (!result.isPresent()) {
return StalenessCheckResult.stale("Document %s missing from index", project);
}
SetMultimap<Project.NameKey, RefState> indexedRefStates = RefState.parseStates(result.get().getValue(ProjectField.REF_STATE));
SetMultimap<Project.NameKey, RefState> currentRefStates = MultimapBuilder.hashKeys().hashSetValues().build();
projectData.tree().stream().filter(p -> p.getProject().getConfigRefState() != null).forEach(p -> currentRefStates.put(p.getProject().getNameKey(), RefState.create(RefNames.REFS_CONFIG, p.getProject().getConfigRefState())));
if (currentRefStates.equals(indexedRefStates)) {
return StalenessCheckResult.notStale();
}
return StalenessCheckResult.stale("Document has unexpected ref states (%s != %s)", currentRefStates, indexedRefStates);
}
Aggregations