nfsantos commented on code in PR #1276: URL: https://github.com/apache/jackrabbit-oak/pull/1276#discussion_r1461680727
########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/ElasticResultRowAsyncIterator.java: ########## @@ -333,16 +338,25 @@ public void onSuccess(SearchResponse<ObjectNode> searchResponse) { } LOG.trace("Emitting {} search hits, for a total of {} scanned results", searchHits.size(), scannedRows); + + Map<SearchHitListener, Boolean> hitsRecord = searchHitListeners.stream() + .collect(HashMap::new, (m, v) -> m.put(v, Boolean.FALSE), HashMap::putAll); + for (Hit<ObjectNode> hit : searchHits) { for (SearchHitListener l : searchHitListeners) { - l.on(hit); + boolean anyHitProcessed = hitsRecord.get(l); + boolean processed = l.on(hit); + hitsRecord.put(l, anyHitProcessed || processed); } Review Comment: I think this can be simplified. We are only interested to know if there is some listener which did not process any hit. This can be done by keeping a set of SearchHitListeners, initially empty. Then when there is an hit for a particular listener, add it to the set. At the end of the iteration, if the set contains all listeners, then all of them had hits. Otherwise, we know that one did not have any hits. This should be simpler than the current approach. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org