fix(convex): corrigir memory leak com .collect() sem limite e adicionar otimizacoes
Problema: Convex backend consumindo 16GB+ de RAM causando OOM kills Correcoes aplicadas: - Substituido todos os .collect() por .take(LIMIT) em 27+ arquivos - Adicionado indice by_usbPolicyStatus para otimizar query de maquinas - Corrigido N+1 problem em alerts.ts usando Map lookup - Corrigido full table scan em usbPolicy.ts - Corrigido subscription leaks no frontend (tickets-view, use-ticket-categories) - Atualizado versao do Convex backend para precompiled-2025-12-04-cc6af4c Arquivos principais modificados: - convex/*.ts - limites em todas as queries .collect() - convex/schema.ts - novo indice by_usbPolicyStatus - convex/alerts.ts - N+1 fix com Map - convex/usbPolicy.ts - uso do novo indice - src/components/tickets/tickets-view.tsx - skip condicional - src/hooks/use-ticket-categories.ts - skip condicional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4b46b08ba
commit
638faeb287
33 changed files with 139 additions and 128 deletions
|
|
@ -64,7 +64,7 @@ export const list = query({
|
|||
.query("deviceFields")
|
||||
.withIndex("by_tenant_order", (q) => q.eq("tenantId", tenantId))
|
||||
|
||||
const fields = await fieldsQuery.collect()
|
||||
const fields = await fieldsQuery.take(100)
|
||||
return fields
|
||||
.filter((field) => matchesCompany(field.companyId, companyId, true))
|
||||
.filter((field) => matchesScope(field.scope, scope))
|
||||
|
|
@ -96,7 +96,7 @@ export const listForTenant = query({
|
|||
const fields = await ctx.db
|
||||
.query("deviceFields")
|
||||
.withIndex("by_tenant_order", (q) => q.eq("tenantId", tenantId))
|
||||
.collect()
|
||||
.take(100)
|
||||
|
||||
return fields
|
||||
.filter((field) => matchesCompany(field.companyId, companyId, false))
|
||||
|
|
@ -153,7 +153,7 @@ export const create = mutation({
|
|||
const existing = await ctx.db
|
||||
.query("deviceFields")
|
||||
.withIndex("by_tenant_order", (q) => q.eq("tenantId", args.tenantId))
|
||||
.collect()
|
||||
.take(100)
|
||||
const maxOrder = existing.reduce((acc, item) => Math.max(acc, item.order ?? 0), 0)
|
||||
const now = Date.now()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue