Skip to content

Commit

Permalink
HSEARCH-3517 Use fetchHits on fetchSingleHit
Browse files Browse the repository at this point in the history
So that fetchSingleHit will be optimized as well
  • Loading branch information
fax4ever committed Sep 1, 2020
1 parent f595960 commit 15eaba9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Expand Up @@ -236,8 +236,8 @@ SearchException unableToParseTemporal(@FormatWith(SimpleNameClassFormatter.class
@Message(id = ID_OFFSET_2 + 60, value = "Invalid '%1$s' value for enum '%2$s'.")
SearchException invalidStringForEnum(String value, @FormatWith(ClassFormatter.class) Class<? extends Enum> enumType, @Cause Exception cause);

@Message(id = ID_OFFSET_2 + 61, value = "Multiple hits when a single hit was expected: got %1$s hits.")
SearchException nonSingleHit(long totalHitCount);
@Message(id = ID_OFFSET_2 + 61, value = "Multiple hits when a single hit was expected.")
SearchException nonSingleHit();

@Message(id = ID_OFFSET_2 + 62,
value = "The thread was interrupted while a work was being submitted to '%1$s'."
Expand Down
Expand Up @@ -61,14 +61,13 @@ public List<H> fetchHits(Integer offset, Integer limit) {
@Override
public Optional<H> fetchSingleHit() {
// We don't need to fetch more than two elements to detect a problem
R result = fetch( 2 );
List<H> hits = result.hits();
int fetchedHitCount = result.hits().size();
List<H> hits = fetchHits( 2 );
int fetchedHitCount = hits.size();
if ( fetchedHitCount == 0 ) {
return Optional.empty();
}
else if ( fetchedHitCount > 1 ) {
throw log.nonSingleHit( result.totalHitCount() );
throw log.nonSingleHit();
}
else {
return Optional.of( hits.get( 0 ) );
Expand Down

0 comments on commit 15eaba9

Please sign in to comment.