-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance updates in self.update_user_groups method #230
Conversation
The |
Group tests fails, so I'm not sure if this works as intended? |
@JonasKs ahh thx! didn't see that they failed at the time. I reverted it back to set. |
Codecov Report
@@ Coverage Diff @@
## master #230 +/- ##
======================================
Coverage 86.0% 86.0%
======================================
Files 11 11
Lines 515 515
======================================
Hits 443 443
Misses 72 72
|
This looks good to me. @sondrelg, @tim-schilling , opinions? 😊 |
Could you please explain how list(existing_groups.iterator()) + new_groups is more performant than this? existing_groups + new_groups I'm sure it could be, but to me it just looks like extra steps 🙂 |
@sondrelg |
Ah yeah I see 👍 That being said, I'm not sure the from django.contrib.auth.models import Group
g = Group.objects.all()
print(list(g) == list(g.iterator()))
>> True I could be wrong though 🙂 Another alternative to combining lists here might be to merge querysets (if Otherwise, looks good to me! |
This looks good to me. It reminds me that I need to find time to do that benchmarking on #220 |
Hey @theognis1002 , could you address @sondrelg's comment so we can merge? 😊 |
existing_groups = list(Group.objects.filter(name__in=claim_groups).iterator()) | ||
existing_group_names = frozenset(group.name for group in existing_groups) | ||
existing_groups = Group.objects.filter(name__in=claim_groups) | ||
existing_group_names = frozenset(existing_groups.values_list("name", flat=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This values_list
call will generate a SQL query and the lazyexisting_groups
is casted to list later (one query), the new code adds a new SQL query.
I'm closing this since we merged #255. If you feel that this still improves the situation, please rebase on main and re-open the PR. |
Made some very slight performance updates in the self.update_user_groups method.
values_list()
retrieves a subset of data without the overhead of creating model instances