diff options
Diffstat (limited to 'java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java')
-rw-r--r-- | java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java b/java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java index b7731bf93b..79449139dc 100644 --- a/java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java +++ b/java/com/google/gerrit/server/git/SearchingChangeCacheImpl.java @@ -41,10 +41,10 @@ import com.google.inject.Singleton; import com.google.inject.TypeLiteral; import com.google.inject.name.Named; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.stream.Stream; import org.eclipse.jgit.lib.Repository; /** @@ -104,24 +104,25 @@ public class SearchingChangeCacheImpl * Additional stored fields are not loaded from the index. * * @param project project to read. - * @param repo repository for the project to read. - * @return Collection of known changes; empty if no changes. + * @param unusedrepo repository for the project to read. + * @return stream of known changes; empty if no changes. */ @Override - public Collection<ChangeData> getChangeDatas(Project.NameKey project, Repository unusedrepo) { + public Stream<ChangeData> streamChangeDatas(Project.NameKey project, Repository unusedrepo) { + List<CachedChange> cached; try { - List<CachedChange> cached = cache.get(project); - List<ChangeData> cds = new ArrayList<>(cached.size()); - for (CachedChange cc : cached) { - ChangeData cd = changeDataFactory.create(cc.change()); - cd.setReviewers(cc.reviewers()); - cds.add(cd); - } - return Collections.unmodifiableList(cds); + cached = cache.get(project); } catch (ExecutionException e) { logger.atWarning().withCause(e).log("Cannot fetch changes for %s", project); - return Collections.emptyList(); + return Stream.empty(); } + return cached.stream() + .map( + cc -> { + ChangeData cd = changeDataFactory.create(cc.change()); + cd.setReviewers(cc.reviewers()); + return cd; + }); } @Override |