mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
Move stringify_message_dict into to_dict_uncached.
This commit is contained in:
@@ -16,7 +16,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
||||
Client, DefaultStream, UserPresence, Referral, PushDeviceToken, MAX_SUBJECT_LENGTH, \
|
||||
MAX_MESSAGE_LENGTH, get_client, get_stream, get_recipient, get_huddle, \
|
||||
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
|
||||
to_dict_cache_key, get_realm, stringify_message_dict, bulk_get_recipients, \
|
||||
to_dict_cache_key, get_realm, bulk_get_recipients, \
|
||||
email_allowed_for_realm, email_to_username, display_recipient_cache_key, \
|
||||
get_user_profile_by_email, get_stream_cache_key, to_dict_cache_key_id, \
|
||||
UserActivityInterval, get_active_user_dicts_in_realm, get_active_streams, \
|
||||
@@ -2488,9 +2488,9 @@ def do_update_message(user_profile, message_id, subject, propagate_mode, content
|
||||
for changed_message in changed_messages:
|
||||
event['message_ids'].append(changed_message.id)
|
||||
items_for_remote_cache[to_dict_cache_key(changed_message, True)] = \
|
||||
(stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=True)),)
|
||||
(changed_message.to_dict_uncached(apply_markdown=True),)
|
||||
items_for_remote_cache[to_dict_cache_key(changed_message, False)] = \
|
||||
(stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=False)),)
|
||||
(changed_message.to_dict_uncached(apply_markdown=False),)
|
||||
cache_set_many(items_for_remote_cache)
|
||||
|
||||
def user_info(um):
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import Any, Dict, Callable, Tuple
|
||||
from django.conf import settings
|
||||
from zerver.models import Message, UserProfile, Stream, get_stream_cache_key, \
|
||||
Recipient, get_recipient_cache_key, Client, get_client_cache_key, \
|
||||
Huddle, huddle_hash_cache_key, to_dict_cache_key_id, stringify_message_dict
|
||||
Huddle, huddle_hash_cache_key, to_dict_cache_key_id
|
||||
from zerver.lib.cache import cache_with_key, cache_set, \
|
||||
user_profile_by_email_cache_key, user_profile_by_id_cache_key, \
|
||||
get_remote_cache_time, get_remote_cache_requests, cache_set_many
|
||||
@@ -31,7 +31,7 @@ def message_fetch_objects():
|
||||
|
||||
def message_cache_items(items_for_remote_cache, message):
|
||||
# type: (Dict[text_type, Tuple[Message]], Message) -> None
|
||||
items_for_remote_cache[to_dict_cache_key_id(message.id, True)] = (stringify_message_dict(message.to_dict_uncached(True)),)
|
||||
items_for_remote_cache[to_dict_cache_key_id(message.id, True)] = (message.to_dict_uncached(True),)
|
||||
|
||||
def user_cache_items(items_for_remote_cache, user_profile):
|
||||
# type: (Dict[text_type, Tuple[UserProfile]], UserProfile) -> None
|
||||
|
||||
@@ -870,9 +870,12 @@ class Message(ModelReprMixin, models.Model):
|
||||
@cache_with_key(to_dict_cache_key, timeout=3600*24)
|
||||
def to_dict_json(self, apply_markdown):
|
||||
# type: (bool) -> binary_type
|
||||
return stringify_message_dict(self.to_dict_uncached(apply_markdown))
|
||||
return self.to_dict_uncached(apply_markdown)
|
||||
|
||||
def to_dict_uncached(self, apply_markdown):
|
||||
return stringify_message_dict(self.to_dict_uncached_helper(apply_markdown))
|
||||
|
||||
def to_dict_uncached_helper(self, apply_markdown):
|
||||
# type: (bool) -> Dict[str, Any]
|
||||
return Message.build_message_dict(
|
||||
apply_markdown = apply_markdown,
|
||||
|
||||
@@ -722,7 +722,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
def check_message(self, msg_id, subject=None, content=None):
|
||||
msg = Message.objects.get(id=msg_id)
|
||||
cached = msg.to_dict(False)
|
||||
uncached = msg.to_dict_uncached(False)
|
||||
uncached = msg.to_dict_uncached_helper(False)
|
||||
self.assertEqual(cached, uncached)
|
||||
if subject:
|
||||
self.assertEqual(msg.subject, subject)
|
||||
|
||||
@@ -612,8 +612,8 @@ class GetOldMessagesTest(AuthedTestCase):
|
||||
m = self.get_last_message()
|
||||
m.rendered_content = m.rendered_content_version = None
|
||||
m.content = 'test content'
|
||||
# Use to_dict_uncached directly to avoid having to deal with remote cache
|
||||
d = m.to_dict_uncached(True)
|
||||
# Use to_dict_uncached_helper directly to avoid having to deal with remote cache
|
||||
d = m.to_dict_uncached_helper(True)
|
||||
self.assertEqual(d['content'], '<p>test content</p>')
|
||||
|
||||
def common_check_get_old_messages_query(self, query_params, expected):
|
||||
|
||||
Reference in New Issue
Block a user