From 84114ab31f75d8157db352f95bb975a0d06d0957 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 25 Dec 2015 17:13:42 -0800 Subject: [PATCH] Simplify realm_user_count to do just do a database count() query. Just doing the database query is more readable, and has about the same performance as before in the case where active user dicts for the realm are in cache (and is substantially better in the rare case that this isn't in the cache). Thanks to @dbiollo for the perf investigation and suggestion! --- zerver/lib/actions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 9fc400853f..6e6d6cc9bf 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -112,8 +112,7 @@ def bot_owner_userids(user_profile): return active_user_ids(user_profile.realm) def realm_user_count(realm): - user_dicts = get_active_user_dicts_in_realm(realm) - return len([user_dict for user_dict in user_dicts if not user_dict["is_bot"]]) + return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False).count() def send_signup_message(sender, signups_stream, user_profile, internal=False, realm=None):