SalesSheet.ai — Code Diff: Null Bug Fix
fix: use parameterized query for contact matching
lib/email/contact-matcher.ts
@@ -42,12 +42,15 @@ function matchSenderToContact()
42 async function matchSenderToContact(senderEmail: string | null) {
43- const { data } = await supabase
44- .from('contacts')
45- .select('id, name')
46- .eq('email', COALESCE(senderEmail, ''));
47- // WHERE contact_id = null ← full table scan!
43+ if (!senderEmail) return null; // early return
44+
45+ const { data } = await supabase
46+ .from('contacts')
47+ .select('id, name')
48+ .eq('email', senderEmail);
49+ // WHERE contact_id = $1 ← uses index!
50 return data?.[0] ?? null;
51 }
Before
47ms
Full table scan on every null sender email
After
0.7ms
Indexed lookup with parameterized query