[keycloak-user] User REST API: n+1 selects

Adrian Gonzalez adr_gonzalez at yahoo.fr
Mon Feb 12 16:56:22 EST 2018


 As a workaround for issue 2, we can activate Permissions in realm-management Client (I've created a custom realm to avoid working on master realm).This way, we ensure root.realmResourceServer() is not null.But that's a bit convoluted :(
 
    Le lundi 12 février 2018 à 22:37:08 UTC+1, Adrian Gonzalez <adr_gonzalez at yahoo.fr> a écrit :  
 
 Hello,
I'm testing KC 3.4.3 REST API and I get n+1 selects (aka 701 selects when asking for a page of 100 users).

Issue 1:Looking at the code, there's n+1 select on the following fields UserEntity: - attributes- requiredActions- credentials 7The n+1 select is triggered by https://github.com/keycloak/keycloak/blob/8e53ccf5abb4d7cc3ab8d5abc9d078a7f8725e8a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java#L215
This can be solved by annotated these attributes with @Fetch(FetchMode.SUBSELECT).I also tried using EntityGraph, but it doesn't work since we're using Collection types (instead of Set) and because we're doing pagination while fetching ToMany associations.

Issue 2: n+1 select because we don't cache null values
We have this select executed n times:select    resourcese0_.ID as ID1_60_0_,    resourcese0_.ALLOW_RS_REMOTE_MGMT as ALLOW_RS2_60_0_,    resourcese0_.POLICY_ENFORCE_MODE as POLICY_E3_60_0_ from    RESOURCE_SERVER resourcese0_ where    resourcese0_.ID=?
This one is done here:https://github.com/keycloak/keycloak/blob/8e53ccf5abb4d7cc3ab8d5abc9d078a7f8725e8a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java#L216

In default setup,root.realmResourceServer() is null.Since StoreFactoryCacheSession doesn't cache null values, the return value never gets cached.I don't know how to easily solve that one.
Should I create an issue ?
Thanks 





  


More information about the keycloak-user mailing list