diff --git a/weblate/trans/models/project.py b/weblate/trans/models/project.py index ca6f5e488194..861bb48fe243 100644 --- a/weblate/trans/models/project.py +++ b/weblate/trans/models/project.py @@ -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 @@ -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