Skip to content

Commit

Permalink
Merge branch 'master' into bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Oct 13, 2014
2 parents d7fc93d + 645ad68 commit c6c8232
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions weblate/trans/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Group
from django.core.cache import cache
import os
import os.path
from weblate.lang.models import Language
Expand Down Expand Up @@ -66,10 +67,21 @@ def get_acl_status(self, user):
and flag whether there is any filtering active.
"""
projects = self.all()
project_ids = [
project.id for project in projects if project.has_acl(user)
]
if projects.count() == len(project_ids):

cache_key = 'acl-project-{0}'.format(user.id)

last_result = cache.get(cache_key)
if last_result is not None:
all_projects, project_ids = last_result
else:
project_ids = [
project.id for project in projects if project.has_acl(user)
]
all_projects = (projects.count() == len(project_ids))

cache.set(cache_key, (all_projects, project_ids))

if all_projects:
return projects, False
return self.filter(id__in=project_ids), True

Expand Down

0 comments on commit c6c8232

Please sign in to comment.