From 053543e6eb9f073aa53a7f9ef1c190400b9b0220 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 9 Jan 2013 13:17:08 -0500 Subject: [PATCH] tornado: Remove normal-runtime query in the user pointers code path. We still need to do an initial query to get the pointers for all users. (imported from commit 6ee991a648faf46539fd8676890dedb5f2003d05) --- zephyr/tornadoviews.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zephyr/tornadoviews.py b/zephyr/tornadoviews.py index 90d6c17ebf..e95dc235c2 100644 --- a/zephyr/tornadoviews.py +++ b/zephyr/tornadoviews.py @@ -57,8 +57,15 @@ def receive(user_profile_id, message): # to the cache. user_pointers = {} def get_user_pointer(user_profile_id): + if user_pointers == {}: + # Once, on startup, fill in the user_pointers table with + # everyone's current pointers + for u in UserProfile.objects.all(): + user_pointers[u.id] = u.pointer if user_profile_id not in user_pointers: - user_pointers[user_profile_id] = UserProfile.objects.get(id=user_profile_id).pointer + # This is a new user created since Tornado was started, so + # they will have an initial pointer of -1. + return -1 return user_pointers[user_profile_id] def set_user_pointer(user_profile_id, pointer):