Skip to content

Commit

Permalink
Updated get_user_projects cache
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Jan 17, 2024
1 parent 330be4b commit fd7d69d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/projects/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def get_user_projects(username=None, limit=5, set_on_none=True):
cache_str = f'_user_project_cache_{username}'
projects_qs = django_cache.get(cache_str)
if projects_qs is None and set_on_none:
projects_qs = Project.objects.filter(
owner__username__iexact=username
projects_qs = Project.objects.has_access_by_username(
username
).order_by('-updated')[:limit]
django_cache.set(cache_str, projects_qs)
return projects_qs
10 changes: 10 additions & 0 deletions src/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def has_access(self, user=None):
Q(projectuser__user=user,
projectuser__active=True)
)
def has_access_by_username(self, username=None):
# Added off video recordings
# for the project cache
if username is None:
return self.none()
return self.filter(
Q(owner__username__iexact=username) |
Q(projectuser__user__username__iexact=username,
projectuser__active=True)
)

class ProjectManager(models.Manager):
def get_queryset(self):
Expand Down

0 comments on commit fd7d69d

Please sign in to comment.