Uploaded image for project: 'Keycloak'
  1. Keycloak
  2. KEYCLOAK-4964

Performance issue - fetching composite roles causes N+1 query

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Cannot Reproduce
    • None
    • None
    • None
    • None
    • NEW
    • NEW

    Description

      The following block of code in RoleAdapter causes an N+1 query since composite roles are lazily loaded

          @Override
          public Set<RoleModel> getComposites() {
              Set<RoleModel> set = new HashSet<RoleModel>();
      
              for (RoleEntity composite : getEntity().getCompositeRoles()) {
                  set.add(new RoleAdapter(session, realm, em, composite));
      
                  // todo I want to do this, but can't as you get stack overflow
                  // set.add(session.realms().getRoleById(composite.getId(), realm));
              }
              return set;
          }
      

      We should probably pre-load the user's roles and the composite roles to avoid lazy querying as part of TokenManager.getAccess

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            meetoblivion_jira John Ament (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: