mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
tornado: Remove UserProfile database queries from notify_new_message.
(imported from commit a23ce0cf7b8497e2ba7bc048d6fcf373f7ad913d)
This commit is contained in:
@@ -46,8 +46,8 @@ def add_pointer_update_callback(user_profile, cb):
|
|||||||
callbacks_table.add(user_profile.id, Callbacks.TYPE_POINTER_UPDATE, cb)
|
callbacks_table.add(user_profile.id, Callbacks.TYPE_POINTER_UPDATE, cb)
|
||||||
|
|
||||||
# The user receives this message
|
# The user receives this message
|
||||||
def receive(user_profile, message):
|
def receive(user_profile_id, message):
|
||||||
callbacks_table.call(user_profile.id, Callbacks.TYPE_RECEIVE,
|
callbacks_table.call(user_profile_id, Callbacks.TYPE_RECEIVE,
|
||||||
messages=[message], update_types=["new_messages"])
|
messages=[message], update_types=["new_messages"])
|
||||||
|
|
||||||
# Simple caching implementation module for user pointers
|
# Simple caching implementation module for user pointers
|
||||||
@@ -78,9 +78,7 @@ def notify_new_message(request):
|
|||||||
if request.POST["users"] == "":
|
if request.POST["users"] == "":
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
# FIXME: better query
|
recipient_profile_ids = map(int, json_to_list(request.POST['users']))
|
||||||
users = [UserProfile.objects.get(id=user)
|
|
||||||
for user in json_to_list(request.POST['users'])]
|
|
||||||
message = Message.objects.get(id=request.POST['message'])
|
message = Message.objects.get(id=request.POST['message'])
|
||||||
|
|
||||||
# Cause message.to_dict() to return the dicts already rendered in the other process.
|
# Cause message.to_dict() to return the dicts already rendered in the other process.
|
||||||
@@ -90,8 +88,8 @@ def notify_new_message(request):
|
|||||||
# (see send_with_safety_check). It's probably not a big deal.
|
# (see send_with_safety_check). It's probably not a big deal.
|
||||||
message.precomputed_dicts = simplejson.loads(request.POST['rendered'])
|
message.precomputed_dicts = simplejson.loads(request.POST['rendered'])
|
||||||
|
|
||||||
for user_profile in users:
|
for user_profile_id in recipient_profile_ids:
|
||||||
receive(user_profile, message)
|
receive(user_profile_id, message)
|
||||||
|
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user