mirror of https://github.com/zulip/zulip.git
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)
This commit is contained in:
parent
37f8cc9294
commit
8190cdc9fb
|
@ -3,6 +3,7 @@ var compose_fade = (function () {
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
var focused_recipient;
|
var focused_recipient;
|
||||||
|
var any_messages_faded = false;
|
||||||
|
|
||||||
exports.set_focused_recipient = function (recipient) {
|
exports.set_focused_recipient = function (recipient) {
|
||||||
focused_recipient = recipient;
|
focused_recipient = recipient;
|
||||||
|
@ -13,8 +14,15 @@ exports.unfade_messages = function (clear_state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!any_messages_faded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row")
|
rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row")
|
||||||
.removeClass("faded").addClass("unfaded");
|
.removeClass("faded").addClass("unfaded");
|
||||||
|
|
||||||
|
any_messages_faded = false;
|
||||||
|
|
||||||
if (clear_state === true) {
|
if (clear_state === true) {
|
||||||
focused_recipient = undefined;
|
focused_recipient = undefined;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +60,7 @@ function _update_faded_messages() {
|
||||||
if (!elt.hasClass("faded")) {
|
if (!elt.hasClass("faded")) {
|
||||||
elt.removeClass("unfaded").addClass("faded");
|
elt.removeClass("unfaded").addClass("faded");
|
||||||
}
|
}
|
||||||
|
any_messages_faded = true;
|
||||||
} else {
|
} else {
|
||||||
if (!elt.hasClass("unfaded")) {
|
if (!elt.hasClass("unfaded")) {
|
||||||
elt.removeClass("faded").addClass("unfaded");
|
elt.removeClass("faded").addClass("unfaded");
|
||||||
|
|
Loading…
Reference in New Issue