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

feat (cache): impl. soft-delete of users in cache #5173

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

jimlambrt
Copy link
Collaborator

@jimlambrt jimlambrt commented Oct 12, 2024

Previously, when all the auth tokens for a user
where deleted, we deleted the user along with all
the cached resources for that user. This can
create a lot of churn in the cache, especially if
the auth tokens have a short TTL (like 8 hrs), which
can cause all the resources to be reloaded every
morning when the user logs in.

This change introduces a soft-delete of users in
the cache. When all the auth tokens for a user are
deleted, but there's still a valid refresh token
that's less than 20 days old, we mark the user as
deleted in the cache and do not return the user in
the list of users returned by the cache, but we
still keep the user in the cache (all all their
cached resources). This way, when the user logs in
again, we can just mark the user as active again
and not have to reload all the resources. If
the refresh token is older than 20 days, we delete
the user from the cache along with all their cached
resources.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Looks great, some minor questions

internal/clientcache/internal/cache/repository_token.go Outdated Show resolved Hide resolved
internal/clientcache/internal/db/db.go Outdated Show resolved Hide resolved
internal/clientcache/internal/db/schema.sql Outdated Show resolved Hide resolved
internal/db/read_writer.go Show resolved Hide resolved
Previously, when all the auth tokens for a user
where deleted, we deleted the user along with all
the cached resources for that user.  This can
create a lot of churn in the cache, especially if
the auth tokens have a short TTL (like 8 hrs), which
can cause all the resources to be reloaded every
morning when the user logs in.

This change introduces a soft-delete of users in
the cache.  When all the auth tokens for a user are
deleted, but there's still a valid refresh token
that's less than 20 days old, we mark the user as
deleted in the cache and do not return the user in
the list of users returned by the cache, but we
still keep the user in the cache (all all their
cached resources). This way, when the user logs in
again, we can just mark the user as active again
and not have to reload all the resources.  If
the refresh token is older than 20 days, we delete
the user from the cache along with all their cached
resources.
@jimlambrt jimlambrt force-pushed the jimlambrt-soft-delete-user-from-cache branch from 1f83d14 to 6f9674d Compare October 18, 2024 13:44
@jimlambrt jimlambrt merged commit ffd0d2a into main Oct 18, 2024
61 of 62 checks passed
@jimlambrt jimlambrt deleted the jimlambrt-soft-delete-user-from-cache branch October 18, 2024 14:33
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.

3 participants