send_message: Use a memcached for the UserProfile-by-id cache.

This cache should save 2 database queries whenever we send a private
message.  However, previously it was per-process (which meant it was
mostly useless) and also buggy (it never stored anything in the cache,
so that it was completely useless).  Switching this to our standard
memcached setup will address both problems.

(imported from commit 1d807f30704bccf28de33a80523488aedc58a9be)
This commit is contained in:
Tim Abbott
2013-03-18 12:10:45 -04:00
parent c1d3a5b5e5
commit 9909c8dc19
3 changed files with 8 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ from django.utils import timezone
from zephyr.lib.create_user import create_user
from zephyr.lib.bulk_create import batch_bulk_create
from zephyr.lib import bugdown
from zephyr.lib.cache import cache_with_key, user_profile_by_id_cache_key
import subprocess
import simplejson
@@ -122,10 +123,8 @@ def log_message(message):
if not message.sending_client.name.startswith("test:"):
log_event(message.to_log_dict())
user_hash = {}
@cache_with_key(user_profile_by_id_cache_key)
def get_user_profile_by_id(uid):
if uid in user_hash:
return user_hash[uid]
return UserProfile.objects.select_related().get(id=uid)
def do_send_message(message, rendered_content=None, no_log=False,