Skip to content
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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

TCMeldrum
Copy link
Contributor

@TCMeldrum TCMeldrum commented Dec 12, 2024

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

  1. The method getRolesForUser in the StfcUserAuthorization class has been updated to fetch roles from StfcUserDataSource instead of directly from the client.
  2. A new cache uowsRawRolesCache has been introduced in the StfcUserDataSource class to store raw STFC roles.
  3. The method getRolesForUser in the StfcUserDataSource 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.
  4. The method getUserRoles in the StfcUserDataSource class has been updated to use the getRolesForUser 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?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@TCMeldrum TCMeldrum marked this pull request as ready for review December 13, 2024 10:56
@TCMeldrum TCMeldrum requested a review from a team as a code owner December 13, 2024 10:56
@TCMeldrum TCMeldrum requested review from mutambaraf and removed request for a team December 13, 2024 10:56
await client.getRolesForUser(process.env.EXTERNAL_AUTH_TOKEN, userNumber)
)?.return;
const stfcRoles: stfcRole[] | null = await (
this.userDataSource as StfcUserDataSource
Copy link
Contributor

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>>(
Copy link
Contributor

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?

@TCMeldrum TCMeldrum requested a review from ACLay December 16, 2024 15:15
Copy link
Contributor

@jekabs-karklins jekabs-karklins left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExternalTokenLogin is very slow for stfc
3 participants