user_groups: Make get_user_group_direct_members query efficient.

This commit makes the query in get_user_group_direct_members
efficient by directly fetching user-profile ids instead of
first fetching user profile object and then id.
This commit is contained in:
Sahil Batra 2021-10-12 15:17:36 +05:30
parent 1a3d67ad0c
commit b65aadae4b
1 changed files with 3 additions and 2 deletions

View File

@ -84,8 +84,9 @@ def create_user_group(
def get_user_group_direct_members(user_group: UserGroup) -> List[UserProfile]:
members = UserGroupMembership.objects.filter(user_group=user_group)
return [member.user_profile.id for member in members]
return UserGroupMembership.objects.filter(user_group=user_group).values_list(
"user_profile_id", flat=True
)
def get_direct_memberships_of_users(user_group: UserGroup, members: List[UserProfile]) -> List[int]: