From 82df424146531ba53f61f3b84933283a73eeb4f4 Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 13 Dec 2018 18:11:06 +0100 Subject: [PATCH] core: put User.group's names in cache --- core/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index 0c1b900e..f96b7881 100644 --- a/core/models.py +++ b/core/models.py @@ -366,7 +366,11 @@ class User(AbstractBaseUser): return False if group_id == settings.SITH_GROUP_ROOT_ID and self.is_superuser: return True - return self.groups.filter(name=group_name).exists() + return group_name in self.cached_groups_names + + @cached_property + def cached_groups_names(self): + return [g.name for g in self.groups.all()] @cached_property def is_root(self):