fix(memory-util): fixed unbounded array of gmail/outlook pollers causing high memory util, added missing db indexes/removed unused ones, auto-disable schedules/webhooks after 10 consecutive failures (#2115)

* fix(memory-util): fixed unbounded array of gmail/outlook pollers causing high memory util, added missing db indexes/removed unused ones, auto-disable schedules/webhooks after 10 consecutive failures

* ack PR comments

* ack
This commit is contained in:
Waleed
2025-11-25 14:15:46 -08:00
committed by GitHub
parent d413bcdfb0
commit 7b7586d093
12 changed files with 8145 additions and 180 deletions

View File

@@ -0,0 +1,8 @@
DROP INDEX "doc_kb_uploaded_at_idx";--> statement-breakpoint
DROP INDEX "workflow_blocks_workflow_type_idx";--> statement-breakpoint
DROP INDEX "workflow_deployment_version_workflow_id_idx";--> statement-breakpoint
DROP INDEX "workflow_execution_logs_execution_id_idx";--> statement-breakpoint
ALTER TABLE "webhook" ADD COLUMN "failed_count" integer DEFAULT 0;--> statement-breakpoint
ALTER TABLE "webhook" ADD COLUMN "last_failed_at" timestamp;--> statement-breakpoint
CREATE INDEX "idx_account_on_account_id_provider_id" ON "account" USING btree ("account_id","provider_id");--> statement-breakpoint
CREATE INDEX "idx_webhook_on_workflow_id_block_id" ON "webhook" USING btree ("workflow_id","block_id");

File diff suppressed because it is too large Load Diff

View File

@@ -778,6 +778,13 @@
"when": 1763667488537,
"tag": "0111_solid_dreadnoughts",
"breakpoints": true
},
{
"idx": 112,
"version": "7",
"when": 1764095386986,
"tag": "0112_tired_blink",
"breakpoints": true
}
]
}

View File

@@ -84,6 +84,10 @@ export const account = pgTable(
},
(table) => ({
userIdIdx: index('account_user_id_idx').on(table.userId),
accountProviderIdx: index('idx_account_on_account_id_provider_id').on(
table.accountId,
table.providerId
),
})
)
@@ -188,7 +192,6 @@ export const workflowBlocks = pgTable(
},
(table) => ({
workflowIdIdx: index('workflow_blocks_workflow_id_idx').on(table.workflowId),
workflowTypeIdx: index('workflow_blocks_workflow_type_idx').on(table.workflowId, table.type),
})
)
@@ -300,7 +303,6 @@ export const workflowExecutionLogs = pgTable(
},
(table) => ({
workflowIdIdx: index('workflow_execution_logs_workflow_id_idx').on(table.workflowId),
executionIdIdx: index('workflow_execution_logs_execution_id_idx').on(table.executionId),
stateSnapshotIdIdx: index('workflow_execution_logs_state_snapshot_id_idx').on(
table.stateSnapshotId
),
@@ -476,6 +478,8 @@ export const webhook = pgTable(
provider: text('provider'), // e.g., "whatsapp", "github", etc.
providerConfig: json('provider_config'), // Store provider-specific configuration
isActive: boolean('is_active').notNull().default(true),
failedCount: integer('failed_count').default(0), // Track consecutive failures
lastFailedAt: timestamp('last_failed_at'), // When the webhook last failed
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow(),
},
@@ -483,6 +487,11 @@ export const webhook = pgTable(
return {
// Ensure webhook paths are unique
pathIdx: uniqueIndex('path_idx').on(table.path),
// Optimize queries for webhooks by workflow and block
workflowBlockIdx: index('idx_webhook_on_workflow_id_block_id').on(
table.workflowId,
table.blockId
),
}
}
)
@@ -1024,12 +1033,10 @@ export const document = pgTable(
uploadedAt: timestamp('uploaded_at').notNull().defaultNow(),
},
(table) => ({
// Primary access pattern - documents by knowledge base
// Primary access pattern - filter by knowledge base
knowledgeBaseIdIdx: index('doc_kb_id_idx').on(table.knowledgeBaseId),
// Search by filename (for search functionality)
// Search by filename
filenameIdx: index('doc_filename_idx').on(table.filename),
// Order by upload date (for listing documents)
kbUploadedAtIdx: index('doc_kb_uploaded_at_idx').on(table.knowledgeBaseId, table.uploadedAt),
// Processing status filtering
processingStatusIdx: index('doc_processing_status_idx').on(
table.knowledgeBaseId,
@@ -1458,7 +1465,6 @@ export const workflowDeploymentVersion = pgTable(
createdBy: text('created_by'),
},
(table) => ({
workflowIdIdx: index('workflow_deployment_version_workflow_id_idx').on(table.workflowId),
workflowVersionUnique: uniqueIndex('workflow_deployment_version_workflow_version_unique').on(
table.workflowId,
table.version