Cleanup guardian-based complexity in get_realm_user_dicts.

The old code for this lookup was unnecessarily complicated because we
were working around Guardian, where the `is_realm_admin` check was
extremely expensive.
This commit is contained in:
Tim Abbott
2016-04-27 14:14:23 -07:00
parent 2a2cbd60c3
commit 0161d2fddd
2 changed files with 2 additions and 5 deletions

View File

@@ -2426,11 +2426,8 @@ def get_status_dict(requesting_user_profile):
def get_realm_user_dicts(user_profile): def get_realm_user_dicts(user_profile):
# Due to our permission model, it is advantageous to find the admin users in bulk.
admins = user_profile.realm.get_admin_users()
admin_emails = set([up.email for up in admins])
return [{'email' : userdict['email'], return [{'email' : userdict['email'],
'is_admin' : userdict['email'] in admin_emails, 'is_admin' : userdict['is_realm_admin'],
'is_bot' : userdict['is_bot'], 'is_bot' : userdict['is_bot'],
'full_name' : userdict['full_name']} 'full_name' : userdict['full_name']}
for userdict in get_active_user_dicts_in_realm(user_profile.realm)] for userdict in get_active_user_dicts_in_realm(user_profile.realm)]

View File

@@ -268,7 +268,7 @@ def cache_save_user_profile(user_profile):
# type: (Any) -> None # type: (Any) -> None
cache_set(user_profile_by_id_cache_key(user_profile.id), user_profile, timeout=3600*24*7) cache_set(user_profile_by_id_cache_key(user_profile.id), user_profile, timeout=3600*24*7)
active_user_dict_fields = ['id', 'full_name', 'short_name', 'email', 'is_bot'] active_user_dict_fields = ['id', 'full_name', 'short_name', 'email', 'is_realm_admin', 'is_bot']
def active_user_dicts_in_realm_cache_key(realm): def active_user_dicts_in_realm_cache_key(realm):
# type: (Any) -> str # type: (Any) -> str
return "active_user_dicts_in_realm:%s" % (realm.id,) return "active_user_dicts_in_realm:%s" % (realm.id,)