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

User per-role cache key for the organization_profile_viewset #2665

Merged
merged 10 commits into from
Aug 21, 2024

Conversation

FrankApiyo
Copy link
Member

@FrankApiyo FrankApiyo commented Aug 14, 2024

Changes / Features implemented

  • Invalidate cache when organization permissions are updated
  • User per-role cache key for the organization_profile_viewset

Steps taken to verify this change does what is intended

  • Updated tests

Side effects of implementing this change

N/A

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Closes #2672

Also, invalidate cache when user x organization permissions are updated

Co-authored-by: Kelvin Muchiri <[email protected]>
@FrankApiyo FrankApiyo force-pushed the use-per-role-cache-key-for-organization-profile branch from b062185 to cebcded Compare August 14, 2024 13:23
@FrankApiyo FrankApiyo marked this pull request as ready for review August 14, 2024 13:31
@FrankApiyo FrankApiyo changed the title [WIP]User per-role cache key for the organization_profile_viewset User per-role cache key for the organization_profile_viewset Aug 14, 2024
@@ -36,6 +38,14 @@
User = get_user_model()


def invalidate_organization_cache(org_username):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this to logger_tools?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've moved it to cache_tools instead

cache.set(f"{ORG_PROFILE_CACHE}{username}{request.user.username}", organization)
organization_profile = OrganizationProfile.objects.get(user__username=username)
cache_key = get_cache_key(request.user, organization_profile)
cache.set(cache_key, organization)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use set_cache_for_org here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@FrankApiyo I've just realized set_cache_for_org is in test_tasks and not in this file

return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)

serializer.save()

data = OrganizationSerializer(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use instead self.get_serializer_class

@FrankApiyo FrankApiyo force-pushed the use-per-role-cache-key-for-organization-profile branch from 09b94e3 to 332b9c0 Compare August 19, 2024 16:47
@FrankApiyo FrankApiyo force-pushed the use-per-role-cache-key-for-organization-profile branch from 332b9c0 to ba44d71 Compare August 19, 2024 16:53
@FrankApiyo FrankApiyo merged commit f328ba8 into main Aug 21, 2024
10 checks passed
@FrankApiyo FrankApiyo deleted the use-per-role-cache-key-for-organization-profile branch August 21, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When running tasks asynchronously, organization profile cache becomes stale when adding/removing users
3 participants