Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_store: Skip parsing messages that have no narrow links.
Evy Kassirer1ea3f47df225
diff --git a/web/src/message_store.ts b/web/src/message_store.tsindex 64200e8acc5..4a65c5ee4c6 100644--- a/web/src/message_store.ts+++ b/web/src/message_store.ts@@ -725,6 +725,10 @@ export function save_topic_links(message: Message): void {if (muted_users.is_user_muted(message.sender_id)) {return;}+ // Parsing HTML is expensive, and most messages have no narrow links.+ if (!message.content.includes("#narrow/")) {+ return;+ }// Extract the URLs from the message content.const link_elements = new DOMParser()diff --git a/web/tests/message_store.test.cjs b/web/tests/message_store.test.cjsindex c77b2b122da..90b17d5fcdc 100644--- a/web/tests/message_store.test.cjs+++ b/web/tests/message_store.test.cjs@@ -607,6 +607,13 @@ test("save_topic_links", () => {message_store.save_topic_links(message_with_content(`<div><a href='${link}'>a link!</a>`));assert_maps_empty();+ // Same when the message only mentions a narrow link without linking to one.+ link = "https://example.com";+ message_store.save_topic_links(+ message_with_content(`<div><a href='${link}'>see #narrow/channel/10-design</a>`),+ );+ assert_maps_empty();+// Malformed link doesn't throw an errorlink = "/#narrow/which-channel/10-design/bad-topic/hello/";message_store.save_topic_links(message_with_content(`<div><a href='${link}'>a link!</a>`));