django-auth-adfs icon indicating copy to clipboard operation
django-auth-adfs copied to clipboard

Performance updates in self.update_user_groups method

Open theognis1002 opened this issue 3 years ago β€’ 10 comments

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

theognis1002 avatar Apr 08 '22 19:04 theognis1002

The values_list changes look good, but can you explain why it makes sense to replace set with add? I'm not that familiar with this code, so just want to know your reasoning before diving in further πŸ™‚

sondrelg avatar Apr 09 '22 18:04 sondrelg

Group tests fails, so I'm not sure if this works as intended?

JonasKs avatar Apr 10 '22 14:04 JonasKs

@JonasKs ahh thx! didn't see that they failed at the time. I reverted it back to set.

theognis1002 avatar Apr 11 '22 13:04 theognis1002

Codecov Report

Merging #230 (e94bb5a) into master (5067f8f) will not change coverage. The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #230   +/-   ##
======================================
  Coverage    86.0%   86.0%           
======================================
  Files          11      11           
  Lines         515     515           
======================================
  Hits          443     443           
  Misses         72      72           
Impacted Files Coverage Ξ”
django_auth_adfs/backend.py 85.8% <100.0%> (ΓΈ)

codecov[bot] avatar Apr 11 '22 13:04 codecov[bot]

This looks good to me.

@sondrelg, @tim-schilling , opinions? 😊

JonasKs avatar Apr 11 '22 15:04 JonasKs

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 avatar Apr 11 '22 17:04 sondrelg

@sondrelg list(existing_groups.iterator()) was just taken from L213 and moved down. This was so that the queryset would not be evaluated before it was needed

theognis1002 avatar Apr 11 '22 20:04 theognis1002

Ah yeah I see πŸ‘

That being said, I'm not sure the iterator() call is worth keeping. Doing a little testing, it seems like the list call is all that's needed.

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 new_groups's queryset is available), using the pipe (|) operator.

Otherwise, looks good to me!

sondrelg avatar Apr 11 '22 20:04 sondrelg

This looks good to me. It reminds me that I need to find time to do that benchmarking on #220

tim-schilling avatar Apr 12 '22 12:04 tim-schilling

Hey @theognis1002 , could you address @sondrelg's comment so we can merge? 😊

JonasKs avatar May 06 '22 13:05 JonasKs

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.

tim-schilling avatar Oct 10 '22 16:10 tim-schilling