From c0029319f997a81bf49aa5d40b7ebc3a05520738 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 12 Jul 2023 15:19:38 +0530 Subject: [PATCH] users: Pass realm as arg to select_related in fetch_users_by_id. This commit updates select_related call to pass "realm" as argument in select_related call in fetch_users_by_id function as we only require realm for the UserProfile objects fetched using fetch_users_by_id. Also, note that "realm" is the only non-null foreign key field in UserProfile object, so select_related() was only fetching realm object previously as well. But we should still pass "realm" as argument in select_related call so that we can make sure that only required fields are selected in case we add more foreign keys to UserProfile in future. --- zerver/lib/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 6e57bd9bf1..be3c5a0cd2 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -223,7 +223,7 @@ def user_ids_to_users(user_ids: Sequence[int], realm: Realm) -> List[UserProfile # users should be included. def fetch_users_by_id(user_ids: List[int]) -> List[UserProfile]: - return list(UserProfile.objects.filter(id__in=user_ids).select_related()) + return list(UserProfile.objects.filter(id__in=user_ids).select_related("realm")) user_profiles_by_id: Dict[int, UserProfile] = bulk_cached_fetch( cache_key_function=user_profile_by_id_cache_key,