message_list_data_cache: Cache MessageListData objects.

We start caching MessageListData objects for the narrows which
user has visited. We restore the cached objects if the filters
match. Also, the cached objects are updated based on events. One
major piece is update path the is pending implementation is the
message move code path.
This commit is contained in:
Aman Agrawal
2024-08-12 09:23:25 +00:00
committed by Tim Abbott
parent 259e77fbf6
commit 5b9a2584c5
9 changed files with 177 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ import $ from "jquery";
import * as inbox_util from "./inbox_util";
import type {MessageListData} from "./message_list_data";
import * as message_list_data_cache from "./message_list_data_cache";
import type {Message} from "./message_store";
import * as ui_util from "./ui_util";
@@ -132,6 +133,7 @@ export function update_current_message_list(msg_list: MessageList | undefined):
current = msg_list;
if (current !== undefined) {
rendered_message_lists.set(current.id, current);
message_list_data_cache.add(current.data);
current.view.$list.addClass("focused-message-list");
}
}
@@ -140,6 +142,16 @@ export function all_rendered_message_lists(): MessageList[] {
return [...rendered_message_lists.values()];
}
export function non_rendered_data(): MessageListData[] {
const rendered_data = new Set(rendered_message_lists.keys());
return message_list_data_cache.all().filter((data) => {
if (data.rendered_message_list_id === undefined) {
return true;
}
return !rendered_data.has(data.rendered_message_list_id);
});
}
export function add_rendered_message_list(msg_list: MessageList): void {
rendered_message_lists.set(msg_list.id, msg_list);
}