avatar: Fix memcached query loop fetching bots.

Similar to the related issue with users, the new avatar storage had
accidentally added database queries in a loop to this code path.
This commit is contained in:
Tim Abbott 2017-05-09 22:09:28 -07:00
parent 8e47dc73bd
commit 0990246289
2 changed files with 3 additions and 3 deletions

View File

@ -327,6 +327,7 @@ def active_user_dicts_in_realm_cache_key(realm):
bot_dict_fields = ['id', 'full_name', 'short_name', 'email', bot_dict_fields = ['id', 'full_name', 'short_name', 'email',
'is_active', 'default_sending_stream__name', 'is_active', 'default_sending_stream__name',
'realm_id',
'default_events_register_stream__name', 'default_events_register_stream__name',
'default_all_public_streams', 'api_key', 'default_all_public_streams', 'api_key',
'bot_owner__email', 'avatar_source', 'bot_owner__email', 'avatar_source',

View File

@ -1377,7 +1377,7 @@ def get_owned_bot_dicts(user_profile, include_all_realm_bots_if_admin=True):
result = UserProfile.objects.filter(realm=user_profile.realm, is_bot=True, result = UserProfile.objects.filter(realm=user_profile.realm, is_bot=True,
bot_owner=user_profile).values(*bot_dict_fields) bot_owner=user_profile).values(*bot_dict_fields)
# TODO: Remove this import cycle # TODO: Remove this import cycle
from zerver.lib.avatar import get_avatar_url from zerver.lib.avatar import avatar_url_from_dict
return [{'email': botdict['email'], return [{'email': botdict['email'],
'user_id': botdict['id'], 'user_id': botdict['id'],
@ -1388,8 +1388,7 @@ def get_owned_bot_dicts(user_profile, include_all_realm_bots_if_admin=True):
'default_events_register_stream': botdict['default_events_register_stream__name'], 'default_events_register_stream': botdict['default_events_register_stream__name'],
'default_all_public_streams': botdict['default_all_public_streams'], 'default_all_public_streams': botdict['default_all_public_streams'],
'owner': botdict['bot_owner__email'], 'owner': botdict['bot_owner__email'],
'avatar_url': get_avatar_url(botdict['avatar_source'], botdict['email'], 'avatar_url': avatar_url_from_dict(botdict),
botdict['avatar_version']),
} }
for botdict in result] for botdict in result]