diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java index 77b364c4b1..672d12a4ef 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java @@ -322,6 +322,9 @@ public class LuceneChangeIndex implements ChangeIndex { IndexSearcher[] searchers = new IndexSearcher[indexes.size()]; try { int realLimit = opts.start() + opts.limit(); + if (Integer.MAX_VALUE - opts.limit() < opts.start()) { + realLimit = Integer.MAX_VALUE; + } TopFieldDocs[] hits = new TopFieldDocs[indexes.size()]; for (int i = 0; i < indexes.size(); i++) { searchers[i] = indexes.get(i).acquire(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java index f84599d85d..60d9c08bdb 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java @@ -73,6 +73,11 @@ public class AbandonUtil { int count = 0; for (ChangeData cd : changesToAbandon) { try { + if (noNeedToAbandon(cd, query)){ + log.debug("Change data \"{}\" does not satisfy the query \"{}\" any" + + " more, hence skipping it in clean up", cd, query); + continue; + } abandon.abandon(changeControl(cd), cfg.getAbandonMessage()); count++; } catch (ResourceConflictException e) { @@ -90,6 +95,14 @@ public class AbandonUtil { } } + private boolean noNeedToAbandon(ChangeData cd, String query) + throws OrmException, QueryParseException { + String newQuery = query + " change:" + cd.getId(); + List changesToAbandon = queryProcessor.enforceVisibility(false) + .query(queryBuilder.parse(newQuery)).entities(); + return changesToAbandon.isEmpty(); + } + private ChangeControl changeControl(ChangeData cd) throws OrmException { return cd.changeControl(internalUserFactory.create()); }