Improve is_member query perf and add schoolyear to query

Summary:
- Changed count() for exists() for better perfs
- Queryset is now filtered on account AND schoolyear to prevent old members to be still marked as currently member of the association

Test Plan:
- Join an organization
- Check that you've successfully joined it (/associations/)
- Create a new Schoolyear in DB
- Check that you're no longer a member of the association

Reviewers: corbeaumax

Reviewed By: corbeaumax

Spies: Armteck

Maniphest Tasks: T71

Differential Revision: https://phabricator.atilla.org/D35
parent 9e317046
......@@ -67,8 +67,8 @@ class Association(models.Model):
def is_member(self, user):
if user.is_authenticated():
a = Account.objects.get(user=user)
if (self.membership_set.filter(account=a).count() > 0):
return True
s = SchoolYear.objects.last()
return self.membership_set.filter(account=a, year=s).exists()
return False
......
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