mirror of https://github.com/zulip/zulip.git
Use get_user_profile_by_* functions to get UserProfiles.
We had a few bugs where we were using a raw Django database query to get a UserProfile object. This might seem OK, but going through memcached is more efficient, and also guarantees that we get back the .select_related() version of the object, so that if we later access related fields like user_profile.realm.domain, we don't end up doing a second database query as well. Fixing these should in practice save a substantial number of database queries on handling update_status_list requests, which happen very often and access user_profile.realm.domain. (imported from commit 0a2027da1b5bbc7a4f6c6927aca498530d7a4977)
This commit is contained in:
parent
2ee31f46cb
commit
e55eb53297
|
@ -21,7 +21,7 @@ class EmailAuthBackend(object):
|
|||
return None
|
||||
|
||||
try:
|
||||
user_profile = UserProfile.objects.get(email__iexact=username)
|
||||
user_profile = get_user_profile_by_email(username)
|
||||
if user_profile.check_password(password):
|
||||
return user_profile
|
||||
except UserProfile.DoesNotExist:
|
||||
|
|
|
@ -770,7 +770,7 @@ def do_update_user_activity(user_profile, client, query, log_time):
|
|||
activity.save(update_fields=["last_visit", "count"])
|
||||
|
||||
def process_user_activity_event(event):
|
||||
user_profile = UserProfile.objects.get(id=event["user_profile_id"])
|
||||
user_profile = get_user_profile_by_id(event["user_profile_id"])
|
||||
client = get_client(event["client"])
|
||||
log_time = timestamp_to_datetime(event["time"])
|
||||
query = event["query"]
|
||||
|
@ -865,14 +865,14 @@ def update_message_flags(user_profile, operation, flag, messages, all):
|
|||
queue_json_publish("user_activity", event, process_update_message_flags)
|
||||
|
||||
def process_user_presence_event(event):
|
||||
user_profile = UserProfile.objects.get(id=event["user_profile_id"])
|
||||
user_profile = get_user_profile_by_id(event["user_profile_id"])
|
||||
client = get_client(event["client"])
|
||||
log_time = timestamp_to_datetime(event["time"])
|
||||
status = event["status"]
|
||||
return do_update_user_presence(user_profile, client, log_time, status)
|
||||
|
||||
def process_update_message_flags(event):
|
||||
user_profile = UserProfile.objects.get(id=event["user_profile_id"])
|
||||
user_profile = get_user_profile_by_id(event["user_profile_id"])
|
||||
try:
|
||||
until_id = event["until_id"]
|
||||
messages = event["messages"]
|
||||
|
@ -1313,7 +1313,7 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
|
|||
message_ids = [event.get('message_id') for event in missed_email_events]
|
||||
timestamp = timestamp_to_datetime(event.get('timestamp'))
|
||||
|
||||
user_profile = UserProfile.objects.get(id=user_profile_id)
|
||||
user_profile = get_user_profile_by_id(user_profile_id)
|
||||
messages = [um.message for um in UserMessage.objects.filter(user_profile=user_profile,
|
||||
message__id__in=message_ids,
|
||||
flags=~UserMessage.flags.read)]
|
||||
|
|
Loading…
Reference in New Issue