refactor(convex): replace collect() with take() to prevent OOM
- liveChat.ts: limit sessions/messages queries (take 50-500) - tickets.ts: batch delete operations, limit playNext/reassign (take 100-2000) - reports.ts: limit ticket/user/machine queries (take 500-2000) - machines.ts: limit machine queries for registration/listing (take 500) - metrics.ts: limit device health summary (take 200) - users.ts: limit user search in claimInvite (take 5000) - alerts.ts: limit company/alert queries (take 500-1000) - migrations.ts: limit batch operations (take 1000-2000) These changes prevent the Convex backend from loading entire tables into memory, which was causing OOM kills at 16GB and WebSocket disconnections (code 1006). Expected RAM reduction: 60-80% at peak usage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c3eb2d3301
commit
3a37892864
8 changed files with 129 additions and 86 deletions
|
|
@ -664,7 +664,8 @@ const metricResolvers: Record<string, MetricResolver> = {
|
|||
},
|
||||
"devices.health_summary": async (ctx, { tenantId, params }) => {
|
||||
const limit = parseLimit(params, 10)
|
||||
const machines = await ctx.db.query("machines").withIndex("by_tenant", (q) => q.eq("tenantId", tenantId)).collect()
|
||||
// Limita a 200 maquinas para evitar OOM
|
||||
const machines = await ctx.db.query("machines").withIndex("by_tenant", (q) => q.eq("tenantId", tenantId)).take(200)
|
||||
const now = Date.now()
|
||||
const summary = machines
|
||||
.map((machine) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue