mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
Rename userprofile_by_foo cache keys to user_profile_by_foo.
(imported from commit ef398abc48c9b81a3d339ffdce00bae274246d28)
This commit is contained in:
@@ -9,7 +9,8 @@ import simplejson
|
|||||||
from zephyr.lib.cache import cache_with_key
|
from zephyr.lib.cache import cache_with_key
|
||||||
from zephyr.lib.queue import SimpleQueueClient
|
from zephyr.lib.queue import SimpleQueueClient
|
||||||
from zephyr.lib.timestamp import datetime_to_timestamp
|
from zephyr.lib.timestamp import datetime_to_timestamp
|
||||||
from zephyr.lib.cache import userprofile_by_email_cache_key, userprofile_by_user_cache_key
|
from zephyr.lib.cache import user_profile_by_email_cache_key, \
|
||||||
|
user_profile_by_user_cache_key
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@@ -57,11 +58,11 @@ else:
|
|||||||
# I like the all-lowercase name better
|
# I like the all-lowercase name better
|
||||||
require_post = require_POST
|
require_post = require_POST
|
||||||
|
|
||||||
@cache_with_key(userprofile_by_user_cache_key)
|
@cache_with_key(user_profile_by_user_cache_key)
|
||||||
def get_user_profile_by_user_id(user_id):
|
def get_user_profile_by_user_id(user_id):
|
||||||
return UserProfile.objects.select_related().get(user_id=user_id)
|
return UserProfile.objects.select_related().get(user_id=user_id)
|
||||||
|
|
||||||
@cache_with_key(userprofile_by_email_cache_key)
|
@cache_with_key(user_profile_by_email_cache_key)
|
||||||
def get_user_profile_by_email(email):
|
def get_user_profile_by_email(email):
|
||||||
return UserProfile.objects.select_related().get(user__email__iexact=email)
|
return UserProfile.objects.select_related().get(user__email__iexact=email)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from zephyr.lib.create_user import create_user
|
|||||||
from zephyr.lib.bulk_create import batch_bulk_create
|
from zephyr.lib.bulk_create import batch_bulk_create
|
||||||
from zephyr.lib import bugdown
|
from zephyr.lib import bugdown
|
||||||
from zephyr.lib.cache import cache_with_key, user_profile_by_id_cache_key, \
|
from zephyr.lib.cache import cache_with_key, user_profile_by_id_cache_key, \
|
||||||
userprofile_by_email_cache_key
|
user_profile_by_email_cache_key
|
||||||
from zephyr.decorator import get_user_profile_by_email, json_to_list
|
from zephyr.decorator import get_user_profile_by_email, json_to_list
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -108,7 +108,7 @@ def compute_mit_user_fullname(email):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return email.lower()
|
return email.lower()
|
||||||
|
|
||||||
@cache_with_key(lambda realm, email: userprofile_by_email_cache_key(email))
|
@cache_with_key(lambda realm, email: user_profile_by_email_cache_key(email))
|
||||||
@transaction.commit_on_success
|
@transaction.commit_on_success
|
||||||
def create_mit_user_if_needed(realm, email):
|
def create_mit_user_if_needed(realm, email):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ def cache(func):
|
|||||||
def message_cache_key(message_id):
|
def message_cache_key(message_id):
|
||||||
return "message:%d" % (message_id,)
|
return "message:%d" % (message_id,)
|
||||||
|
|
||||||
def userprofile_by_email_cache_key(email):
|
def user_profile_by_email_cache_key(email):
|
||||||
return 'user_profile_by_email:%s' % (hashlib.sha1(email).hexdigest(),)
|
return 'user_profile_by_email:%s' % (hashlib.sha1(email).hexdigest(),)
|
||||||
|
|
||||||
def userprofile_by_user_cache_key(user_id):
|
def user_profile_by_user_cache_key(user_id):
|
||||||
return 'user_profile_by_user_id:%d' % (user_id,)
|
return 'user_profile_by_user_id:%d' % (user_id,)
|
||||||
|
|
||||||
def user_profile_by_id_cache_key(user_profile_id):
|
def user_profile_by_id_cache_key(user_profile_id):
|
||||||
@@ -72,8 +72,8 @@ def user_by_id_cache_key(user_id):
|
|||||||
def update_user_profile_cache(sender, **kwargs):
|
def update_user_profile_cache(sender, **kwargs):
|
||||||
user_profile = kwargs['instance']
|
user_profile = kwargs['instance']
|
||||||
items_for_memcached = {}
|
items_for_memcached = {}
|
||||||
items_for_memcached[userprofile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
items_for_memcached[user_profile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
||||||
items_for_memcached[userprofile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
items_for_memcached[user_profile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
||||||
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||||
djcache.set_many(items_for_memcached)
|
djcache.set_many(items_for_memcached)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# loop
|
# loop
|
||||||
from zephyr.models import Message, UserProfile
|
from zephyr.models import Message, UserProfile
|
||||||
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key, \
|
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key, \
|
||||||
userprofile_by_email_cache_key, userprofile_by_user_cache_key, \
|
user_profile_by_email_cache_key, user_profile_by_user_cache_key, \
|
||||||
user_by_id_cache_key, user_profile_by_id_cache_key
|
user_by_id_cache_key, user_profile_by_id_cache_key
|
||||||
|
|
||||||
MESSAGE_CACHE_SIZE = 25000
|
MESSAGE_CACHE_SIZE = 25000
|
||||||
@@ -33,8 +33,8 @@ def populate_message_cache():
|
|||||||
def populate_user_cache():
|
def populate_user_cache():
|
||||||
items_for_memcached = {}
|
items_for_memcached = {}
|
||||||
for user_profile in UserProfile.objects.select_related().all():
|
for user_profile in UserProfile.objects.select_related().all():
|
||||||
items_for_memcached[userprofile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
items_for_memcached[user_profile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
||||||
items_for_memcached[userprofile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
items_for_memcached[user_profile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
||||||
items_for_memcached[user_by_id_cache_key(user_profile.user.id)] = (user_profile.user,)
|
items_for_memcached[user_by_id_cache_key(user_profile.user.id)] = (user_profile.user,)
|
||||||
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user