From f168b8cce97e87585d0af85e905cb310f4c357dc Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Wed, 13 Mar 2024 12:17:01 +0100 Subject: [PATCH] Avoid invalidating the cache if removing an entry doesn't exist Closes #27852 Signed-off-by: Alexander Schwartz --- .../models/cache/infinispan/UserAdapter.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java index 7f3ae6a084..c8fee2dbf3 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java @@ -192,8 +192,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeAttribute(String name) { - getDelegateForUpdate(); - updated.removeAttribute(name); + if (getFirstAttribute(name) != null) { + getDelegateForUpdate(); + updated.removeAttribute(name); + } } @Override @@ -229,8 +231,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeRequiredAction(RequiredAction action) { - getDelegateForUpdate(); - updated.removeRequiredAction(action); + if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action.name()))) { + getDelegateForUpdate(); + updated.removeRequiredAction(action); + } } @Override @@ -241,8 +245,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeRequiredAction(String action) { - getDelegateForUpdate(); - updated.removeRequiredAction(action); + if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action))) { + getDelegateForUpdate(); + updated.removeRequiredAction(action); + } } @Override