message_events: Update edited msgs to be rerendered together.

This significantly reduces the time required to handle events like
stream & topic name edit for topics.

Verified using the Chrome Profiler for a topic with 100 messages:
With this commit: 0.64s to move the topic to a different stream.
Without this commit: 5.5s.
This commit is contained in:
Aman Agrawal 2020-05-17 03:18:44 +05:30 committed by GitHub
parent b234fe8ccb
commit 40c2a82e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -221,6 +221,7 @@ exports.update_messages = function update_messages(events) {
}
}
const messages_to_rerender = [];
for (const id of event.message_ids) {
const msg = message_store.get(id);
if (msg === undefined) {
@ -265,10 +266,11 @@ exports.update_messages = function update_messages(events) {
// remove the message from the current/narrowed message list.
const cur_row = current_msg_list.get_row(id);
if (cur_row !== undefined) {
current_msg_list.remove_and_rerender([{id: id}]);
messages_to_rerender.push({id: id});
}
}
}
current_msg_list.remove_and_rerender(messages_to_rerender);
}
if (event.orig_content !== undefined) {