From 8190cdc9fb6c929a92d8624099dd1cee3bed8770 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 11 Aug 2013 15:34:05 -0400 Subject: [PATCH] Avoid redundant O(N) work in unfade_messages().. The code in unfade_messages() is O(N) over the number of messages, but a simple flag allows us to track the fact that all messages are unfaded, so we can short circuit the O(N) logic in many cases. A typical scenario now would be that you start typing a stream while the topic is still empty. Modulo debouncing, every keystroke now leads to a call to unfade_messages(), but this change only does real work the first time. (imported from commit da07cf408bbdbf5b381ff3ec33a5e05e34eef5b5) --- static/js/compose_fade.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/static/js/compose_fade.js b/static/js/compose_fade.js index de2c27ee05..f0d39bb8a9 100644 --- a/static/js/compose_fade.js +++ b/static/js/compose_fade.js @@ -3,6 +3,7 @@ var compose_fade = (function () { var exports = {}; var focused_recipient; +var any_messages_faded = false; exports.set_focused_recipient = function (recipient) { focused_recipient = recipient; @@ -13,8 +14,15 @@ exports.unfade_messages = function (clear_state) { return; } + if (!any_messages_faded) { + return; + } + rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row") .removeClass("faded").addClass("unfaded"); + + any_messages_faded = false; + if (clear_state === true) { focused_recipient = undefined; } @@ -52,6 +60,7 @@ function _update_faded_messages() { if (!elt.hasClass("faded")) { elt.removeClass("unfaded").addClass("faded"); } + any_messages_faded = true; } else { if (!elt.hasClass("unfaded")) { elt.removeClass("faded").addClass("unfaded");