Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
perf(email): drop the redundant dedupe in attachment discovery (#6331)
Will Hutchinson71f22bafde42
diff --git a/crates/email_db_client/src/attachments/provider/upload.rs b/crates/email_db_client/src/attachments/provider/upload.rsindex 0b06bd1e92..70f611acb1 100644--- a/crates/email_db_client/src/attachments/provider/upload.rs+++ b/crates/email_db_client/src/attachments/provider/upload.rs@@ -193,7 +193,11 @@ pub async fn fetch_job_attachments_for_backfill(JOIN public.email_messages message ON message.thread_id = eligible.thread_idWHERE message.from_contact_id IS NOT NULL- UNION+ -- UNION ALL, not UNION: `qualified_threads` already applies+ -- SELECT DISTINCT to this result, so a set-union dedupe here+ -- sorts the whole participant set only to have the work thrown+ -- away. Duplicates cannot change the final thread set.+ UNION ALLSELECT message.thread_id, recipient.contact_idFROM eligible_threads eligiblediff --git a/crates/macro_db_client/migrations/20260910144341_email_messages_thread_id_from_contact_id_index.sql b/crates/macro_db_client/migrations/20260910144341_email_messages_thread_id_from_contact_id_index.sqlnew file mode 100644index 0000000000..a45b946442--- /dev/null+++ b/crates/macro_db_client/migrations/20260910144341_email_messages_thread_id_from_contact_id_index.sql@@ -0,0 +1,10 @@+-- no-transaction+-- The attachment-discovery query's `participants` CTE+-- (email_db_client::attachments::provider::upload) joins every message of+-- every attachment-bearing thread by thread_id and projects from_contact_id.+-- The existing (thread_id, internal_date_ts) indexes locate the messages but+-- not the contact, so each row costs a heap fetch; this makes that arm+-- index-only.+-- Single statement: see 20260910144339 for the CONCURRENTLY constraint.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_email_messages_thread_id_from_contact_id+ ON email_messages (thread_id, from_contact_id);