Hi,
I am currently having issues with very slow export/import of realms with a large number of users (10K). Both operations take ~10 minutes each.
After digging in the KeyCloak code, I've found out that a lot of "flush" is done at the Hibernate/JPA level (at least 4-5 times per user).
Export:
* Set<FederatedIdentityModel> socialLinks = session.users().getFederatedIdentities(user, realm);
* Set<RoleModel> roles = user.getRoleMappings();
* List<UserConsentModel> consents = user.getConsents();
* for (GroupModel group : user.getGroups()) {
They seem to be caused by Hibernate that forces a flush by default in "getResultList()". As a workaround I told Hibernate to flush only on commit of the transaction through "-Dorg.hibernate.flushMode=COMMIT" and the export time came down to ~20 seconds.
Could there be any issue of changing the flush mode only for the export? Data shouldn't change in the database at this moment and queries shouldn't return stale data.
Import:
If I remove all those flush/detach calls, the import process goes down to ~50 seconds. What is the reason for flushing every time an entity is created rather than letting JPA/Hibernate do it when necessary?
Thank you,
Gabriel
--