Commit 4e6cdda8 by Michael Farrell

Minor optimisation to ACLs (use .exists() instead of bool() because it's…

Minor optimisation to ACLs (use .exists() instead of bool() because it's faster), fix an issue on Django 1.5 where EmptyQuerySet has no method select_related_common()
parent 76b06989
......@@ -57,7 +57,7 @@ class Article(models.Model):
if user == self.owner:
return True
if self.group_read:
if self.group and user.groups.filter(id=self.group.id):
if self.group and user.groups.filter(id=self.group.id).exists():
return True
if self.can_moderate(user):
return True
......@@ -74,7 +74,7 @@ class Article(models.Model):
if user == self.owner:
return True
if self.group_write:
if self.group and user and user.groups.filter(id=self.group.id):
if self.group and user and user.groups.filter(id=self.group.id).exists():
return True
if self.can_moderate(user):
return True
......
......@@ -60,6 +60,8 @@ class URLPath(MPTTModel):
If the cached ancestors were not set explicitly, they will be retrieved from
the database.
"""
if not self.get_ancestors().exists():
self._cached_ancestors = []
if not hasattr(self, "_cached_ancestors"):
self._cached_ancestors = list(self.get_ancestors().select_related_common() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment