Skip to content

Commit

Permalink
Cache validationGroups for subsequent requests
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Jan 22, 2024
1 parent 5856d2e commit 7d9688d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -56,6 +56,7 @@
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @author Yanming Zhou
* @since 3.1
*/
public class InvocableHandlerMethod extends HandlerMethod {
Expand All @@ -78,6 +79,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
@Nullable
private MethodValidator methodValidator;

@Nullable
private Class<?>[] validationGroups;


/**
* Create an instance from a {@code HandlerMethod}.
Expand Down Expand Up @@ -180,7 +184,10 @@ public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewC
logger.trace("Arguments: " + Arrays.toString(args));
}

Class<?>[] groups = getValidationGroups();
Class<?>[] groups = this.validationGroups;
if (groups == null) {
groups = this.validationGroups = this.getValidationGroups();
}
if (shouldValidateArguments() && this.methodValidator != null) {
this.methodValidator.applyArgumentValidation(
getBean(), getBridgedMethod(), getMethodParameters(), args, groups);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -64,6 +64,7 @@
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @author Yanming Zhou
* @since 5.0
*/
public class InvocableHandlerMethod extends HandlerMethod {
Expand All @@ -87,6 +88,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
@Nullable
private MethodValidator methodValidator;

@Nullable
private Class<?>[] validationGroups;


/**
* Create an instance from a {@code HandlerMethod}.
Expand Down Expand Up @@ -166,7 +170,10 @@ public Mono<HandlerResult> invoke(
ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) {

return getMethodArgumentValues(exchange, bindingContext, providedArgs).flatMap(args -> {
Class<?>[] groups = getValidationGroups();
Class<?>[] groups = this.validationGroups;
if (groups == null) {
groups = this.validationGroups = this.getValidationGroups();
}
if (shouldValidateArguments() && this.methodValidator != null) {
this.methodValidator.applyArgumentValidation(
getBean(), getBridgedMethod(), getMethodParameters(), args, groups);
Expand Down

0 comments on commit 7d9688d

Please sign in to comment.