Skip to content

Commit ec4f129

Browse files
committed
Check the new groups are different before update
Claimed groups can contain groups they are not relevant for our app so the first quick check is to ensure the list are different then to use a SQL query to fetch the groups of the user. Only set the groups if they are different, it avoids a SELECT of the Django ORM (called by the set()).
1 parent 77748cb commit ec4f129

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

django_auth_adfs/backend.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ def update_user_groups(self, user, claim_groups):
382382
if sorted(claim_groups) != sorted(user_group_names):
383383
# Get the list of already existing groups in one SQL query
384384
existing_claimed_groups = Group.objects.filter(name__in=claim_groups)
385+
existing_claimed_group_names = (
386+
group.name for group in existing_claimed_groups
387+
)
388+
389+
if sorted(existing_claimed_group_names) == sorted(user_group_names):
390+
# If the groups are already set, we don't need to do anything
391+
return
385392

386393
if settings.MIRROR_GROUPS:
387394
existing_claimed_group_names = (

0 commit comments

Comments
 (0)