Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_events: Bulk remove messages in stream_topic_history.

Aman Agrawale82fe09cfc92
diff --git a/web/src/message_events.js b/web/src/message_events.js
index 4a76d42c08d..c63000c6f2c 100644
--- a/web/src/message_events.js
+++ b/web/src/message_events.js
@@ -288,6 +288,7 @@ export function update_messages(events) {
}
}
// The event.message_ids received from the server are not in sorted order.
+ // Sorts in ascending order.
event_messages.sort((a, b) => a.id - b.id);
if (
@@ -307,6 +308,18 @@ export function update_messages(events) {
drafts.rename_stream_recipient(old_stream_id, orig_topic, new_stream_id, new_topic);
}
+ // Remove the stream_topic_entry for the old topics;
+ // must be called before we call set message topic.
+ const num_messages = event_messages.length;
+ if (num_messages > 0) {
+ stream_topic_history.remove_messages({
+ stream_id: old_stream_id,
+ topic_name: orig_topic,
+ num_messages,
+ max_removed_msg_id: event_messages[num_messages - 1].id,
+ });
+ }
+
for (const moved_message of event_messages) {
if (realm.realm_allow_edit_history) {
/* Simulate the format of server-generated edit
@@ -335,23 +348,6 @@ export function update_messages(events) {
}
moved_message.last_edit_timestamp = event.edit_timestamp;
- // Remove the stream_topic_entry for the old topics;
- // must be called before we call set message topic.
- //
- // TODO: Use a single bulk request to do this removal.
- // Note that we need to be careful to only remove IDs
- // that were present in stream_topic_history data.
- // This may not be possible to do correctly without extra
- // complexity; the present loop assumes stream_topic_history has
- // only messages in message_store, but that's been false
- // since we added the server_history feature.
- stream_topic_history.remove_messages({
- stream_id: moved_message.stream_id,
- topic_name: moved_message.topic,
- num_messages: 1,
- max_removed_msg_id: moved_message.id,
- });
-
// Update the unread counts; again, this must be called
// before we modify the topic field on the message.
unread.update_unread_topics(moved_message, event);