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!
This commit is contained in:
Tim Abbott
2015-12-25 17:13:42 -08:00
parent 01f613751a
commit 84114ab31f

View File

@@ -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):