From 45b9de1e85cc74e9ed7c9d15d56ff63bbc91d6f0 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 9 Jan 2013 10:42:29 -0500 Subject: [PATCH] tornado: Remove UserProfile database queries from notify_new_message. (imported from commit a23ce0cf7b8497e2ba7bc048d6fcf373f7ad913d) --- zephyr/tornadoviews.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/zephyr/tornadoviews.py b/zephyr/tornadoviews.py index b9f9ac33b0..947448aa33 100644 --- a/zephyr/tornadoviews.py +++ b/zephyr/tornadoviews.py @@ -46,8 +46,8 @@ def add_pointer_update_callback(user_profile, cb): callbacks_table.add(user_profile.id, Callbacks.TYPE_POINTER_UPDATE, cb) # The user receives this message -def receive(user_profile, message): - callbacks_table.call(user_profile.id, Callbacks.TYPE_RECEIVE, +def receive(user_profile_id, message): + callbacks_table.call(user_profile_id, Callbacks.TYPE_RECEIVE, messages=[message], update_types=["new_messages"]) # Simple caching implementation module for user pointers @@ -78,9 +78,7 @@ def notify_new_message(request): if request.POST["users"] == "": return json_success() - # FIXME: better query - users = [UserProfile.objects.get(id=user) - for user in json_to_list(request.POST['users'])] + recipient_profile_ids = map(int, json_to_list(request.POST['users'])) message = Message.objects.get(id=request.POST['message']) # 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. message.precomputed_dicts = simplejson.loads(request.POST['rendered']) - for user_profile in users: - receive(user_profile, message) + for user_profile_id in recipient_profile_ids: + receive(user_profile_id, message) return json_success()