mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 07:52:19 +00:00
tornado: Send rendered messages to Tornado via memcached.
(imported from commit c1e8a017fa61b4e3f5c44ad4e5f59e4faf012ca3)
This commit is contained in:
@@ -150,14 +150,14 @@ def do_send_message(message, no_log=False):
|
||||
|
||||
# We can only publish messages to longpolling clients if the Tornado server is running.
|
||||
if settings.TORNADO_SERVER:
|
||||
# Render Markdown etc. here, so that the single-threaded Tornado server doesn't have to.
|
||||
# TODO: Reduce duplication in what we send.
|
||||
rendered = { 'text/html': message.to_dict(apply_markdown=True),
|
||||
'text/x-markdown': message.to_dict(apply_markdown=False) }
|
||||
# Render Markdown etc. here and store (automatically) in
|
||||
# memcached, so that the single-threaded Tornado server
|
||||
# doesn't have to.
|
||||
message.to_dict(apply_markdown=True)
|
||||
message.to_dict(apply_markdown=False)
|
||||
requests.post(settings.TORNADO_SERVER + '/notify_new_message', data=dict(
|
||||
secret = settings.SHARED_SECRET,
|
||||
message = message.id,
|
||||
rendered = simplejson.dumps(rendered),
|
||||
users = simplejson.dumps([str(user.id) for user in recipients])))
|
||||
|
||||
def create_stream_if_needed(realm, stream_name):
|
||||
|
||||
@@ -171,14 +171,6 @@ class Message(models.Model):
|
||||
|
||||
@cache_with_key(lambda self, apply_markdown: 'message_dict:%d:%d' % (self.id, apply_markdown))
|
||||
def to_dict(self, apply_markdown):
|
||||
# Messages arrive in the Tornado process with the dicts already rendered.
|
||||
# This avoids running the Markdown parser and some database queries in the single-threaded
|
||||
# Tornado server.
|
||||
#
|
||||
# This field is not persisted to the database and will disappear if the object is re-fetched.
|
||||
if hasattr(self, 'precomputed_dicts'):
|
||||
return self.precomputed_dicts['text/html' if apply_markdown else 'text/x-markdown']
|
||||
|
||||
display_recipient = get_display_recipient(self.recipient)
|
||||
if self.recipient.type == Recipient.STREAM:
|
||||
display_type = "stream"
|
||||
|
||||
@@ -139,13 +139,6 @@ def notify_new_message(request):
|
||||
recipient_profile_ids = map(int, json_to_list(request.POST['users']))
|
||||
message = cache_get_message(int(request.POST['message']))
|
||||
|
||||
# Cause message.to_dict() to return the dicts already rendered in the other process.
|
||||
#
|
||||
# We decode this JSON only to eventually re-encode it as JSON.
|
||||
# This isn't trivial to fix, because we do access some fields in the meantime
|
||||
# (see send_with_safety_check). It's probably not a big deal.
|
||||
message.precomputed_dicts = simplejson.loads(request.POST['rendered'])
|
||||
|
||||
for user_profile_id in recipient_profile_ids:
|
||||
receive(user_profile_id, message)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user