fix(search): align global search telemetry with search_analytics schema#338
Conversation
Same bug as #329 fixed in useProductAnalytics.ts but missed in useGlobalSearch.ts. Insert was sending columns that do not exist in public.search_analytics: - seller_id → user_id (column name mismatch) - filters_used → search_context (column does not exist; the schema has search_context text) Validated against live DB (doufsxqlfjyuvxuezpln): search_analytics columns are id, user_id, search_term, results_count, search_context, created_at — no seller_id, no filters_used. Without this fix every global search insert was rejected with PGRST204 (column not found), silently breaking search telemetry. The latency+intent payload is now serialized as JSON into search_context (text) since the new column type is text, not jsonb.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Your plan includes 5 reviews of capacity. Refill in 22 minutes and 51 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
Pull request overview
This PR restores global search telemetry by aligning the search_analytics insert in useGlobalSearch.ts with the live public.search_analytics schema (matching the fix previously applied elsewhere in #329), preventing PGRST204 “column not found” failures and allowing metrics to be recorded again.
Changes:
- Writes
user_idinstead of the non-existentseller_id. - Serializes the telemetry payload into
search_context(text) instead of the non-existentfilters_used.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contexto
Follow-up cirúrgico do #329 (já mergeado). O PR #329 corrigiu o mesmo bug em
useProductAnalytics.ts, mas passou batido emuseGlobalSearch.ts(linha ~713) — que tem o mesmo insert quebrado emsearch_analytics.Bug
O insert estava enviando duas colunas que não existem em
public.search_analytics:seller_id: sellerIduser_idfilters_used: { ... }(jsonb-like)search_context textSchema confirmado via SQL contra o banco vivo (`doufsxqlfjyuvxuezpln`):
```
search_analytics columns:
id uuid NOT NULL
user_id uuid NULL
search_term text NOT NULL
results_count integer NOT NULL
search_context text NULL
created_at timestamptz NOT NULL
```
Impacto runtime: todo insert da busca global retornava `PGRST204` (column not found) silenciosamente, quebrando completamente a telemetria de busca. O `.then(() => undefined, () => undefined)` engolia o erro.
Fix
```diff
```
O payload (`latency_ms` + `intent_type`) é serializado como JSON dentro de `search_context` porque a coluna é `text`, não `jsonb`. Quem for consumir essa telemetria depois pode fazer `(search_context::jsonb)->>'intent_type'` no SQL.
Validação
Por que não foi no #329
O #329 tocou `useProductAnalytics.ts` (telemetria de visualização de produto) mas não `useGlobalSearch.ts` (telemetria de busca global). Mesma tabela, mesma raiz, dois call sites — o segundo foi descoberto na auditoria pós-merge.
Próximo (não escopo deste PR)
A descrição do #329 menciona drift de schema na personalização (`product_group_` / `product_component_` referenciando colunas que não existem no DB). Continua aberto e requer decisão de produto.
Summary by cubic
Fixes global search telemetry to match the
public.search_analyticsschema, preventingPGRST204column errors and restoring metrics collection. Applies the same fix missed inuseGlobalSearch.tsthat was done in #329.user_idinstead ofseller_id.search_context(text) as a JSON string:{ latency_ms, intent_type }.userIdto avoid invalid inserts.Written for commit 07e9b9f. Summary will update on new commits. Review in cubic