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

FORMS-1677: add user caching #1577

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

usingtechnology
Copy link
Collaborator

@usingtechnology usingtechnology commented Jan 14, 2025

To reduce the number of hits to the db for user (login user - parsed token + db id) add a caching layer.

Cache the login user (parsed token + db fields). Caching is limited to 5 minutes - same as our token.

A few important things happen before we read from the cache:

  • the token is parsed
  • the token is verified

If we have a valid token, we can then check the cache. If we get a cache hit, we check to see that the cache version matches the token (token may have been refreshed). If that cache hit is stale, then we discard it and do the normal refresh and hydration of the login user and then cache it.

The login user (current user) is called on nearly all endpoints and currently invokes 2 db hits. Short term caching will reduce db load and therefore improve performance. This caching strategy is not aggressive and has safeguards to prevent returning an invalid user.

This relates to #1579 where we remove forms from the current user and use explicit form queries instead of always making those 2 db hits.

Description

Type of Change

feat (a new feature)

perf (change to improve performance)

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have run the npm script lint on the frontend and backend
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have approval from the product owner for the contribution in this pull request

Further comments

To reduce the number of hits to the db for user (login user and current user) add a caching layer.

Signed-off-by: Jason Sherman <[email protected]>
Copy link
Collaborator

@WalterMoar WalterMoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that as a team we need to discuss this sort of thing before work starts on it.

@usingtechnology
Copy link
Collaborator Author

I think that as a team we need to discuss this sort of thing before work starts on it.

I have no idea when we are going to have a prioritized list of tasks, so got to work on something. Performance is an issue and has been raised by clients. Some analysis has been done on this (no metrics, but when are we going to get metrics?) so good thing as any to get cracking on. This isn't a "look at the files and approve" PR. At least there is something to kick around and test out.

This comment has been minimized.

Copy link

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.

2 participants