From 6653269427947d5b16870dd1276d175d32515717 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 22 Feb 2023 09:19:22 +0100 Subject: [PATCH] # Improve is_shared_with() * improves central is_shared_with() method of ShareableObjectMixin to run ~30% faster --- konova/models/object.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/konova/models/object.py b/konova/models/object.py index a1c8c9c2..90c2f23d 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -501,10 +501,13 @@ class ShareableObjectMixin(models.Model): Returns: """ - directly_shared = self.shared_users.filter(id=user.id).exists() - team_shared = self.shared_teams.filter( - users__in=[user] - ).exists() + obj_shared_teams = self.shared_teams + obj_shared_users = self.shared_users + user_shared_teams = user.shared_teams + + directly_shared = obj_shared_users.filter(id=user.id).exists() + team_shared = (obj_shared_teams & user_shared_teams).exists() + is_shared = directly_shared or team_shared return is_shared