# Improve is_shared_with()

* improves central is_shared_with() method of ShareableObjectMixin to run ~30% faster
This commit is contained in:
mpeltriaux 2023-02-22 09:19:22 +01:00
parent e1259b276c
commit 6653269427

View File

@ -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