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)
This commit is contained in:
Tim Abbott 2013-01-09 13:17:08 -05:00
parent 1a82741650
commit 053543e6eb

View File

@ -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):