-
Notifications
You must be signed in to change notification settings - Fork 9
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
perf: cache raw stfc rolls call #892
base: develop
Are you sure you want to change the base?
Conversation
await client.getRolesForUser(process.env.EXTERNAL_AUTH_TOKEN, userNumber) | ||
)?.return; | ||
const stfcRoles: stfcRole[] | null = await ( | ||
this.userDataSource as StfcUserDataSource |
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.
Is the cast to StfcUserDataSource necessary? It looks like the variable is already typed that way.
@@ -128,6 +128,11 @@ export class StfcUserDataSource implements UserDataSource { | |||
StfcUserDataSource.rolesCacheSecondsToLive | |||
).enableStatsLogging('uowsRolesCache'); | |||
|
|||
private uowsRawRolesCache = new Cache<Promise<stfcRole[] | null>>( |
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.
I see where you're coming from with the raw
names, but I wonder if it might be more intuitive if this new cache was called uowsRolesCache
or stfcRolesCache
and the existing one was renamed to uopRolesCache
?
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.
This looks ok, but one thing I want to ask if maybe this is making more sense to be cached at UOWSSoapClient level rather than datasource.
Of course it is up to you, I'm just thinking that putting it in there seems more logical as if there is another component relying on UOWSSoapClient it would benefit from the cache.
Closes UserOfficeProject/issue-tracker#1290
Description
This PR improves the performance of our application by caching raw STFC roles call.
Motivation and Context
This change is required to optimize the application and reduce unnecessary calls to the STFC service. By caching the raw STFC roles call, we are able to significantly reduce the load time and enhance the user experience.
Changes
getRolesForUser
in theStfcUserAuthorization
class has been updated to fetch roles fromStfcUserDataSource
instead of directly from the client.uowsRawRolesCache
has been introduced in theStfcUserDataSource
class to store raw STFC roles.getRolesForUser
in theStfcUserDataSource
class has been updated to use the newly introduced cache. If the roles are not in the cache, it fetches them from the client, stores them in the cache, and then returns them.getUserRoles
in theStfcUserDataSource
class has been updated to use thegetRolesForUser
method instead of directly calling the client. This allows it to benefit from the caching mechanism.How Has This Been Tested?
Fixes Jira Issue
https://jira.esss.lu.se/browse/
Depends On
Tests included/Docs Updated?