Use more efficient Reactor operators
Use handle/flatMapIterable instead of flatMap/flatMapMany when possible. Closes gh-22727
This commit is contained in:
@@ -441,13 +441,13 @@ class DefaultWebClient implements WebClient {
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(Class<T> elementType) {
|
||||
return this.responseMono.flatMapMany(response ->
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.flatMapMany(Flux::error)));
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementType) {
|
||||
return this.responseMono.flatMapMany(response ->
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.flatMapMany(Flux::error)));
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
}
|
||||
|
||||
private <T extends Publisher<?>> T handleBody(ClientResponse response,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -71,12 +72,15 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageReaderArgu
|
||||
String name = getPartName(parameter, requestPart);
|
||||
|
||||
Flux<Part> parts = exchange.getMultipartData()
|
||||
.flatMapMany(map -> {
|
||||
.flatMapIterable(map -> {
|
||||
List<Part> list = map.get(name);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return (isRequired ? Flux.error(getMissingPartException(name, parameter)) : Flux.empty());
|
||||
if (isRequired) {
|
||||
throw getMissingPartException(name, parameter);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Flux.fromIterable(list);
|
||||
return list;
|
||||
});
|
||||
|
||||
if (Part.class.isAssignableFrom(parameter.getParameterType())) {
|
||||
|
||||
Reference in New Issue
Block a user