-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Avoid touching the database layer if no changes are necessary for a user #43683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Avoid touching the database layer if no changes are necessary for a user #43683
Conversation
423c507 to
89839b0
Compare
Closes keycloak#43682 Signed-off-by: Alexander Schwartz <[email protected]>
89839b0 to
b6d5cf4
Compare
Signed-off-by: Alexander Schwartz <[email protected]>
358f400 to
261b7f5
Compare
| @Override | ||
| public void addRequiredAction(RequiredAction action) { | ||
| if (updated == null && getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action.name()))) { | ||
| return; | ||
| } | ||
| getDelegateForUpdate(); | ||
| updated.addRequiredAction(action); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeRequiredAction(RequiredAction action) { | ||
| if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action.name()))) { | ||
| getDelegateForUpdate(); | ||
| updated.removeRequiredAction(action); | ||
| if (updated == null && getRequiredActionsStream().noneMatch(s -> Objects.equals(s, action.name()))) { | ||
| return; | ||
| } | ||
| getDelegateForUpdate(); | ||
| updated.removeRequiredAction(action); | ||
| } | ||
|
|
||
| @Override | ||
| public void addRequiredAction(String action) { | ||
| if (updated == null && getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action))) { | ||
| return; | ||
| } | ||
| getDelegateForUpdate(); | ||
| updated.addRequiredAction(action); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeRequiredAction(String action) { | ||
| if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action))) { | ||
| getDelegateForUpdate(); | ||
| updated.removeRequiredAction(action); | ||
| if (updated == null && getRequiredActionsStream().noneMatch(s -> Objects.equals(s, action))) { | ||
| return; | ||
| } | ||
| getDelegateForUpdate(); | ||
| updated.removeRequiredAction(action); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid creating and iterating over streams
@Override
public void addRequiredAction(RequiredAction action) {
if (action == null || updated == null && getCachedRequiredActions().contains(action.name())) {
return;
}
getDelegateForUpdate();
updated.addRequiredAction(action);
}
@Override
public void removeRequiredAction(RequiredAction action) {
if (action == null || updated == null && !getCachedRequiredActions().contains(action.name())) {
return;
}
getDelegateForUpdate();
updated.removeRequiredAction(action);
}
@Override
public void addRequiredAction(String action) {
if (updated == null && getCachedRequiredActions().contains(action)) {
return;
}
getDelegateForUpdate();
updated.addRequiredAction(action);
}
@Override
public void removeRequiredAction(String action) {
if (updated == null && !getCachedRequiredActions().contains(action)) {
return;
}
getDelegateForUpdate();
updated.removeRequiredAction(action);
}
private Set<String> getCachedRequiredActions() {
return cached.getRequiredActions(keycloakSession, modelSupplier);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pruivo - please re-review. Thanks!
Signed-off-by: Alexander Schwartz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'm not going to nitpick :)
|
Let's keep this draft until the backports also work in other branches. In #43697, this run makes me think... |
Signed-off-by: Alexander Schwartz <[email protected]>
Closes #43682