update_message_backend: Fix memcached queries in loop.

This fixes a bug where update_message_backend would do one memcached
query per user receiving a given message.  Right now we just do a
single bulk database query, but in principle we could use
generic_bulk_cached_fetch to use the cache as well.
This commit is contained in:
Tim Abbott 2017-01-23 17:07:51 -08:00
parent 0f7f9dc0fb
commit 33b02a02dd

View File

@ -928,9 +928,13 @@ def update_message_backend(request, user_profile,
# probably are not relevant for reprocessed alert_words,
# mentions and similar rendering features. This may be a
# decision we change in the future.
ums = UserMessage.objects.filter(message=message.id,
flags=~UserMessage.flags.historical)
message_users = {get_user_profile_by_id(um.user_profile_id) for um in ums}
ums = UserMessage.objects.filter(
message=message.id,
flags=~UserMessage.flags.historical)
message_users = UserProfile.objects.select_related().filter(
id__in={um.user_profile_id for um in ums})
# We render the message using the current user's realm; since
# the cross-realm bots never edit messages, this should be
# always correct.