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
|
@Override
|
||||||
public Mono<T> one() {
|
public Mono<T> one() {
|
||||||
return all().buffer(2)
|
return all().singleOrEmpty()
|
||||||
.flatMap(list -> {
|
.onErrorMap(IndexOutOfBoundsException.class, ex -> {
|
||||||
if (list.isEmpty()) {
|
String message = String.format("Query [%s] returned non unique result.", resultFunction.getSql());
|
||||||
return Mono.empty();
|
return new IncorrectResultSizeDataAccessException(message, 1);
|
||||||
}
|
});
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue