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

Separate caching of dynamic user vars from permissions #9957

Merged

Conversation

licitdev
Copy link
Member

@licitdev licitdev commented Nov 21, 2021

Closes #9933.

The permissions are now cached based on role in systemCache.

The dynamic user variables are cached in cache per user when CACHE_ENABLED is true.

The cache is cleared upon create, update, and delete actions on items when CACHE_AUTO_PURGE is true.

On a side note, the caching may not be efficient if users are using the app when CACHE_AUTO_PURGE is true. The cache is cleared on every page navigation due to an update being performed in /users/me/track/page. However, that is the intended behaviour in case someone requires to use $CURRENT_USER.last_page in permissions.

Functions extracted

  1. parsePermissions() to parse and extract required dynamic fields
  2. getFilterContext() to fetch dynamic fields only when necessary
  3. processPermissions() to process the filters with the filterContext

@licitdev licitdev marked this pull request as draft November 26, 2021 10:18
@licitdev licitdev marked this pull request as ready for review November 26, 2021 12:42
@rijkvanzanten rijkvanzanten added this to the v9.2.2 milestone Dec 8, 2021
@rijkvanzanten rijkvanzanten self-assigned this Dec 8, 2021
Copy link
Contributor

@azrikahar azrikahar left a comment

Choose a reason for hiding this comment

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

LGTM!

api/src/utils/get-permissions.ts Outdated Show resolved Hide resolved
@rijkvanzanten rijkvanzanten merged commit 709bab1 into directus:main Dec 10, 2021
@licitdev licitdev deleted the fix/dynamic-user-vars-permissions-cache branch December 13, 2021 08:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permissions cache includes dynamic user variables
3 participants