diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index d7d3d582ca..8a5280f485 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -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): diff --git a/zephyr/models.py b/zephyr/models.py index 55d5760557..addf60605d 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -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" diff --git a/zephyr/tornadoviews.py b/zephyr/tornadoviews.py index ad4ae9c2f7..1ee3441727 100644 --- a/zephyr/tornadoviews.py +++ b/zephyr/tornadoviews.py @@ -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)