Use `singleOrEmpty()` instead of `buffer()`
This commit avoids fetching and buffering results in temporary `List` buffers. See gh-31282
This commit is contained in:
parent
2e2a62a23c
commit
cbfb99fef2
|
|
@ -59,18 +59,11 @@ class DefaultFetchSpec<T> implements FetchSpec<T> {
|
|||
|
||||
@Override
|
||||
public Mono<T> one() {
|
||||
return all().buffer(2)
|
||||
.flatMap(list -> {
|
||||
if (list.isEmpty()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
if (list.size() > 1) {
|
||||
return Mono.error(new IncorrectResultSizeDataAccessException(
|
||||
String.format("Query [%s] returned non unique result.", this.resultFunction.getSql()),
|
||||
1));
|
||||
}
|
||||
return Mono.just(list.get(0));
|
||||
}).next();
|
||||
return all().singleOrEmpty()
|
||||
.onErrorMap(IndexOutOfBoundsException.class, ex -> {
|
||||
String message = String.format("Query [%s] returned non unique result.", resultFunction.getSql());
|
||||
return new IncorrectResultSizeDataAccessException(message, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue