RoutePredicateHandlerMapping can be optimized (#3010)

* One optimization method in reactive programming is to reduce the number of nested layers of Flux or Mono, which can not only save memory, but also improve execution efficiency, in theory, there is no need to nest a layer of Mono.

* Optimize unnecessary reactive code to improve operational efficiency

* restore and fix compilation failure

---------

Co-authored-by: manzhizhen <dubbocommitter@gmail.com>
Co-authored-by: yizhenqiang <yizhenqiang@corp.netesase.com>
This commit is contained in:
yizhenqiang
2024-03-09 03:30:06 +08:00
committed by GitHub
parent fbd99eb8c4
commit c4e4d20d44

View File

@@ -88,14 +88,14 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping {
exchange.getAttributes().put(GATEWAY_REACTOR_CONTEXT_ATTR, contextView);
return lookupRoute(exchange)
// .log("route-predicate-handler-mapping", Level.FINER) //name this
.flatMap((Function<Route, Mono<?>>) r -> {
.map((Function<Route, ?>) r -> {
exchange.getAttributes().remove(GATEWAY_PREDICATE_ROUTE_ATTR);
if (logger.isDebugEnabled()) {
logger.debug("Mapping [" + getExchangeDesc(exchange) + "] to " + r);
}
exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, r);
return Mono.just(webHandler);
return webHandler;
}).switchIfEmpty(Mono.empty().then(Mono.fromRunnable(() -> {
exchange.getAttributes().remove(GATEWAY_PREDICATE_ROUTE_ATTR);
if (logger.isTraceEnabled()) {