Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

perf(notification): index the channel-message notification lookup (#8889)

teo75bf092d688f
diff --git a/crates/macro_db_client/migrations/20261027142441_notification_message_id_idx.sql b/crates/macro_db_client/migrations/20261027142441_notification_message_id_idx.sql
new file mode 100644
index 0000000000..c79f3144b5
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261027142441_notification_message_id_idx.sql
@@ -0,0 +1,7 @@
+-- no-transaction
+-- Channel-message notification lookups match this exact expression; without
+-- an index on it, each requested message scans the whole notification table.
+-- Must stay a single statement: sqlx sends no-transaction migrations as
+-- one batch, and CONCURRENTLY cannot run inside a transaction.
+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_notification_message_id
+ ON notification ((COALESCE(metadata->>'messageId', metadata->>'message_id', '')));
diff --git a/crates/notification/src/outbound/entity_notifications.rs b/crates/notification/src/outbound/entity_notifications.rs
index 3eca755579..d26f6dda9d 100644
--- a/crates/notification/src/outbound/entity_notifications.rs
+++ b/crates/notification/src/outbound/entity_notifications.rs
@@ -1,6 +1,6 @@
//! Filtered notification edges, limited independently for every requested entity.
-//! Separate indexed primary/secondary candidate paths keep the legacy JSON
-//! message lookup from forcing a metadata scan for ordinary channel requests.
+//! The primary, secondary and message-id candidate paths each have their own
+//! index; the message-id path's `COALESCE` must match `idx_notification_message_id`.
use std::{collections::HashMap, str::FromStr};