Skip to content

Commit

Permalink
fix: don't execute next paged search if current result count less than (
Browse files Browse the repository at this point in the history
#2171)

allowed row count

Co-authored-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
  • Loading branch information
yuremm and yurem committed Aug 18, 2022
1 parent 8ec5dd3 commit 94a162f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private <O> PagedResult<JsonObject> searchImpl(BucketMapping bucketMapping, Stri

StringBuilder query = null;
int currentLimit;
int lastResultCount = 0;
int lastCountRows = 0;
try {
List<JsonObject> lastSearchResultList;
do {
Expand All @@ -539,26 +539,26 @@ private <O> PagedResult<JsonObject> searchImpl(BucketMapping bucketMapping, Stri
}

lastSearchResultList = lastResult.rowsAsObject();
lastResultCount = lastSearchResultList.size();
lastCountRows = lastSearchResultList.size();

if (batchOperation != null) {
collectSearchResult = batchOperation.collectSearchResult(lastResultCount);
collectSearchResult = batchOperation.collectSearchResult(lastCountRows);
}
if (collectSearchResult) {
searchResultList.addAll(lastSearchResultList);
}

if ((batchOperation != null) && (lastResultCount > 0)) {
if ((batchOperation != null) && (lastCountRows > 0)) {
List<O> entries = batchOperationWraper.createEntities(lastSearchResultList);
batchOperation.performAction(entries);
}

totalEntriesCount += lastResultCount;
totalEntriesCount += lastCountRows;

if ((count > 0) && (totalEntriesCount >= count)) {
if ((count > 0) && (totalEntriesCount >= count) || (lastCountRows < currentLimit)) {
break;
}
} while (lastResultCount > 0);
} while (lastCountRows > 0);
} catch (CouchbaseException ex) {
throw new SearchException("Failed to search entries. Query: '" + query + "'", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ private <O> PagedResult<EntryData> searchImpl(TableMapping tableMapping, String

resultCount += lastCountRows;

if ((count > 0) && (resultCount >= count)) {
if ((count > 0) && (resultCount >= count) || (lastCountRows < currentLimit)) {
break;
}
} while (lastCountRows > 0);
Expand Down

0 comments on commit 94a162f

Please sign in to comment.