-
Notifications
You must be signed in to change notification settings - Fork 150
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
refactor: optimize keycloak interactions #3397
Conversation
…o help reduce group only queries
EDIT: I've updated this PR so this comment is out of date |
97ba276
to
21741cd
Compare
21741cd
to
ce657b5
Compare
This makes some fairly invasive changes to the authentication logic. Would it be possible to add some unit tests around at least |
I don't fully understand testing JS frameworks, but I can look into this. But I'm also curious which parts concern you here, so that I can focus efforts. |
Well I mean all the new code really, but particularly the new JS mapper, and the new functions in Does the mapper put |
It |
…collection from groups using new faster keycloak requests
…m keycloak and processing to cut down on repeated calls within resolvers
…w, and add adminscope checks for some permissions
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.
Functionally LGTM and tested locally. Any nitpicks can be addressed in a follow-up.
Checklist
To improve API performance, a number of changes have been made to keycloak queries to get even more information in the first request to reduce the number of loops that were done previously.
This also removes Redis, as the request times for even large users and groups are considerably faster now than before, but there is still the possibility of refactoring to re-introduce Redis later on, if required.
For example, previously a user in 130 groups could see the
allProjects
query that the UI uses taking over 60 seconds to load on an initial load against the API directly, when no redis cache exists, and still a few seconds to load even when redis cache was used. With these improvements, it is now reduced down to a few milliseconds, without redis.Another example is querying the groups resolver directly, for example, if there were 2000 groups, before this would eventually time out (90seconds +) in the API because it took too long. This now takes a few seconds to return, longer if the members of groups are requested too.
The bulk of the changes are to interactions with groups, by utilising the
briefRepresentation: false
flag when retrieving groups from keycloak, this flag means that attributes of groups are returned in the queries, so this eliminated the requirement to loop over the groups to get the additional information like before.With these improvements, it also means that
hasPermissions
is considerably faster than it was before (even with redis), and previously we had to hardcode a permission override which has now been removed so all queries perform permissions as required, and still see a performance increase.lagoon/services/api/src/resources/project/resolvers.ts
Lines 91 to 99 in f80eb45