Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

models: Remove select_related call in get_active_users.

Sahil Batrabb3945a32f55
diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.py
index d8c64dd4b65..e15f1bafdcd 100644
--- a/zerver/actions/user_settings.py
+++ b/zerver/actions/user_settings.py
@@ -96,7 +96,7 @@ def send_delivery_email_update_events(
@transaction.atomic(savepoint=False)
def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) -> None:
- delete_user_profile_caches([user_profile])
+ delete_user_profile_caches([user_profile], user_profile.realm)
user_profile.delivery_email = new_email
if user_profile.email_address_is_realm_public():
diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py
index 07003e749d6..ed037166965 100644
--- a/zerver/lib/cache.py
+++ b/zerver/lib/cache.py
@@ -510,7 +510,7 @@ def bot_dicts_in_realm_cache_key(realm_id: int) -> str:
return f"bot_dicts_in_realm:{realm_id}"
-def delete_user_profile_caches(user_profiles: Iterable["UserProfile"]) -> None:
+def delete_user_profile_caches(user_profiles: Iterable["UserProfile"], realm: "Realm") -> None:
# Imported here to avoid cyclic dependency.
from zerver.lib.users import get_all_api_keys
from zerver.models import is_cross_realm_bot_email
@@ -520,13 +520,11 @@ def delete_user_profile_caches(user_profiles: Iterable["UserProfile"]) -> None:
keys.append(user_profile_by_id_cache_key(user_profile.id))
for api_key in get_all_api_keys(user_profile):
keys.append(user_profile_by_api_key_cache_key(api_key))
- keys.append(user_profile_cache_key(user_profile.email, user_profile.realm))
- keys.append(
- user_profile_delivery_email_cache_key(user_profile.delivery_email, user_profile.realm)
- )
+ keys.append(user_profile_cache_key(user_profile.email, realm))
+ keys.append(user_profile_delivery_email_cache_key(user_profile.delivery_email, realm))
if user_profile.is_bot and is_cross_realm_bot_email(user_profile.email):
# Handle clearing system bots from their special cache.
- keys.append(bot_profile_cache_key(user_profile.email, user_profile.realm_id))
+ keys.append(bot_profile_cache_key(user_profile.email, realm.id))
cache_delete_many(keys)
@@ -560,7 +558,7 @@ def flush_user_profile(
**kwargs: object,
) -> None:
user_profile = instance
- delete_user_profile_caches([user_profile])
+ delete_user_profile_caches([user_profile], user_profile.realm)
# Invalidate our active_users_in_realm info dict if any user has changed
# the fields in the dict or become (in)active
@@ -600,7 +598,7 @@ def flush_realm(
) -> None:
realm = instance
users = realm.get_active_users()
- delete_user_profile_caches(users)
+ delete_user_profile_caches(users, realm)
if (
from_deletion
diff --git a/zerver/models.py b/zerver/models.py
index d30ea9a5b96..5aa115ce3b3 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -879,7 +879,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
)
def get_active_users(self) -> QuerySet["UserProfile"]:
- return UserProfile.objects.filter(realm=self, is_active=True).select_related()
+ return UserProfile.objects.filter(realm=self, is_active=True)
def get_first_human_user(self) -> Optional["UserProfile"]:
"""A useful value for communications with newly created realms.