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.

feat(email): add effective-date index for latest-message lateral (#4741)

Evan Hutnikbe0da88cb341
diff --git a/crates/macro_db_client/migrations/20260712191131_email_messages_effective_date_index.sql b/crates/macro_db_client/migrations/20260712191131_email_messages_effective_date_index.sql
new file mode 100644
index 0000000000..3adb72429a
--- /dev/null
+++ b/crates/macro_db_client/migrations/20260712191131_email_messages_effective_date_index.sql
@@ -0,0 +1,6 @@
+-- no-transaction
+-- Matches the latest-message lateral's ORDER BY COALESCE(internal_date_ts,
+-- created_at) DESC so the per-thread LIMIT 1 walks newest-first and stops at
+-- the first match instead of reading every message in the thread.
+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_email_messages_thread_id_effective_date_desc
+ ON email_messages (thread_id, COALESCE(internal_date_ts, created_at) DESC);