Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
perf(log): use startedAt index for cleanup query filter
Switch cleanup WHERE clause from createdAt to startedAt to leverage
the existing composite index (workspaceId, startedAt), converting a
full table scan to an index range scan. Also remove explanatory comment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Apr 10, 2026
commit cafe8fe1f9c7e58f4044e10c5354f643ae86a77c
9 changes: 1 addition & 8 deletions apps/sim/app/api/logs/cleanup/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ export async function GET(request: NextRequest) {
const retentionDate = new Date()
retentionDate.setDate(retentionDate.getDate() - Number(env.FREE_PLAN_LOG_RETENTION_DAYS || '7'))

/**
* Subquery: workspace IDs whose billed account user has no active paid
* subscription. Kept as a subquery (not materialized into JS) so the
* generated SQL is `WHERE workspace_id IN (SELECT ...)` — this avoids
* PostgreSQL's 65535 bind-parameter limit that was breaking cleanup once
* the free-user count grew beyond ~65k.
*/
const freeWorkspacesSubquery = db
.select({ id: workspace.id })
.from(workspace)
Expand Down Expand Up @@ -94,7 +87,7 @@ export async function GET(request: NextRequest) {
.where(
and(
inArray(workflowExecutionLogs.workspaceId, freeWorkspacesSubquery),
lt(workflowExecutionLogs.createdAt, retentionDate)
lt(workflowExecutionLogs.startedAt, retentionDate)
Comment thread
waleedlatif1 marked this conversation as resolved.
)
)
.limit(BATCH_SIZE)
Expand Down
Loading