message_util: Avoid unnecessary unreads work processing new messages.

It should be very rare to discover new unread messages during a
message_fetch call. This can potentially happen due to races (fetching
just as a new message arrives), but it shouldn't be the common case.

Previously, we would trigger a full rerender of all UI displaying
unread messages every time a bulk message fetch operation returned
(including every time one narrowed), regardless of whether any actual
state had changed.

Fix this by actually checking if we discovered any new unread messages.
This commit is contained in:
Tim Abbott
2022-10-24 15:34:47 -07:00
parent 505a9119ba
commit 8d33a62eca
6 changed files with 55 additions and 18 deletions

View File

@@ -7,10 +7,15 @@ import * as resize from "./resize";
import * as unread from "./unread";
import * as unread_ui from "./unread_ui";
export function do_unread_count_updates(messages) {
unread.process_loaded_messages(messages);
unread_ui.update_unread_counts();
resize.resize_page_components();
export function do_unread_count_updates(messages, expect_no_new_unreads = false) {
const any_new_unreads = unread.process_loaded_messages(messages, expect_no_new_unreads);
if (any_new_unreads) {
// The following operations are expensive, and thus should
// only happen if we found any unread messages justifying it.
unread_ui.update_unread_counts();
resize.resize_page_components();
}
}
export function add_messages(messages, msg_list, opts) {