Skip to content
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

fix: improve performance when updating member role #1680

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wilsonrivera
Copy link
Contributor

@wilsonrivera wilsonrivera commented Mar 11, 2025

Motivation and Context

When updating member roles the operation could take anywhere from a few seconds to over a minute (eventually failing).

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

Both operations were executed with 7400 organizations.

Before:
before

After:
after

Analysis

The organizations are created as groups inside Keycloak and the roles are subgroups of the organizations.

To find the identifier of the role in Keycloak we were searching by the role name, for example admin, this causes Keycloak to return all the organizations as the admin role should exist in all of them. This issue scales with the amount of organizations created in Keycloak.

Something that added to the issue is that we were performing this operation 3 times in a row to load the relevant organization roles.

Solution

The solution is to use the organization identifier (kcGroupId) to list the subgroups (roles) of the organization and filter them by name.

Additionally, to avoid performing this operation multiple times in a row just with different role, a new method was introduced to load all organization roles at once and filter in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant