groups: Use realm_for_sharding for limiting NamedUserGroup queries.

For get and filter queries of NamedUserGroup, realm_for_sharding
field is used instead of realm field, as directly using
realm_for_sharding field on NamedUserGroup makes the query faster
than using realm present on the base UserGroup table.
This commit is contained in:
Sahil Batra
2025-09-10 12:54:33 +05:30
committed by Tim Abbott
parent d4d7a8fe2a
commit 764f4aa2e0
42 changed files with 573 additions and 436 deletions

View File

@@ -270,7 +270,7 @@ try:
if thread.get("user_groups") is not None:
for user_group in thread.get("user_groups"):
user_grp = NamedUserGroup.objects.filter(
name=user_group["group_name"], realm=realm
name=user_group["group_name"], realm_for_sharding=realm
).first()
if user_grp is not None:
user_grp.delete()

View File

@@ -64,7 +64,7 @@ with test_server_running(
# Iago needs permission to manage all user groups.
admins_group = NamedUserGroup.objects.get(
name=SystemGroups.ADMINISTRATORS, realm=realm, is_system_group=True
name=SystemGroups.ADMINISTRATORS, realm_for_sharding=realm, is_system_group=True
)
do_change_realm_permission_group_setting(
realm, "can_manage_all_groups", admins_group, acting_user=None