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
|
|
@ -103,7 +103,7 @@ export const listAgents = query({
|
|||
const users = await ctx.db
|
||||
.query("users")
|
||||
.withIndex("by_tenant", (q) => q.eq("tenantId", tenantId))
|
||||
.collect();
|
||||
.take(5000);
|
||||
|
||||
// Only internal staff (ADMIN/AGENT) should appear as responsáveis
|
||||
return users
|
||||
|
|
@ -128,7 +128,7 @@ export const listCustomers = query({
|
|||
const users = await ctx.db
|
||||
.query("users")
|
||||
.withIndex("by_tenant", (q) => q.eq("tenantId", tenantId))
|
||||
.collect();
|
||||
.take(5000);
|
||||
|
||||
const allowed = users.filter((user) => {
|
||||
const role = (user.role ?? "COLLABORATOR").toUpperCase()
|
||||
|
|
@ -215,7 +215,7 @@ export const deleteUser = mutation({
|
|||
const comments = await ctx.db
|
||||
.query("ticketComments")
|
||||
.withIndex("by_author", (q) => q.eq("authorId", userId))
|
||||
.collect();
|
||||
.take(10000);
|
||||
if (comments.length > 0) {
|
||||
const authorSnapshot = {
|
||||
name: user.name,
|
||||
|
|
@ -243,7 +243,7 @@ export const deleteUser = mutation({
|
|||
const requesterTickets = await ctx.db
|
||||
.query("tickets")
|
||||
.withIndex("by_tenant_requester", (q) => q.eq("tenantId", user.tenantId).eq("requesterId", userId))
|
||||
.collect();
|
||||
.take(10000);
|
||||
if (requesterTickets.length > 0) {
|
||||
const requesterSnapshot = {
|
||||
name: user.name,
|
||||
|
|
@ -267,7 +267,7 @@ export const deleteUser = mutation({
|
|||
const directReports = await ctx.db
|
||||
.query("users")
|
||||
.withIndex("by_tenant_manager", (q) => q.eq("tenantId", user.tenantId).eq("managerId", userId))
|
||||
.collect();
|
||||
.take(1000);
|
||||
await Promise.all(
|
||||
directReports.map(async (report) => {
|
||||
await ctx.db.patch(report._id, { managerId: undefined });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue