Skip to content

Commit adb8f71

Browse files
address greptile comments
1 parent 28b9847 commit adb8f71

File tree

9 files changed

+30443
-318
lines changed

9 files changed

+30443
-318
lines changed

apps/sim/background/cleanup-logs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@/lib/billing/cleanup-dispatcher'
1111
import { snapshotService } from '@/lib/logs/execution/snapshot/service'
1212
import { isUsingCloudStorage, StorageService } from '@/lib/uploads'
13+
import { deleteFileMetadata } from '@/lib/uploads/server/metadata'
1314

1415
const logger = createLogger('CleanupLogs')
1516

@@ -44,7 +45,6 @@ async function deleteExecutionFiles(files: unknown, results: TierResults): Promi
4445
results.filesTotal++
4546
try {
4647
await StorageService.deleteFile({ key: file.key, context: 'execution' })
47-
const { deleteFileMetadata } = await import('@/lib/uploads/server/metadata')
4848
await deleteFileMetadata(file.key)
4949
results.filesDeleted++
5050
} catch (fileError) {

apps/sim/background/cleanup-soft-deletes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export async function runCleanupSoftDeletes(payload: CleanupJobPayload): Promise
249249
lt(workflow.archivedAt, retentionDate)
250250
)
251251
)
252+
.limit(BATCH_SIZE * MAX_BATCHES_PER_TABLE)
252253

253254
const doomedWorkflowIds = doomedWorkflows.map((w) => w.id)
254255
let chatCleanup: { execute: () => Promise<void> } | null = null

apps/sim/background/cleanup-tasks.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -224,33 +224,17 @@ export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void>
224224
if (r.deleted > 0) logger.info(`[${r.table}] ${r.deleted} deleted`)
225225
}
226226

227-
// Delete feedback — no direct workspaceId, find via copilotChats
227+
// Delete feedback — no direct workspaceId, reuse chat IDs collected above
228228
const feedbackResult: TableCleanupResult = {
229229
table: `${tierLabel}/copilotFeedback`,
230230
deleted: 0,
231231
failed: 0,
232232
}
233233
try {
234-
const chatIds = await db
235-
.select({ id: copilotChats.id })
236-
.from(copilotChats)
237-
.where(
238-
and(
239-
inArray(copilotChats.workspaceId, workspaceIds),
240-
lt(copilotChats.updatedAt, retentionDate)
241-
)
242-
)
243-
.limit(BATCH_SIZE * MAX_BATCHES_PER_TABLE)
244-
245-
if (chatIds.length > 0) {
234+
if (doomedChatIds.length > 0) {
246235
const deleted = await db
247236
.delete(copilotFeedback)
248-
.where(
249-
inArray(
250-
copilotFeedback.chatId,
251-
chatIds.map((c) => c.id)
252-
)
253-
)
237+
.where(inArray(copilotFeedback.chatId, doomedChatIds))
254238
.returning({ id: copilotFeedback.feedbackId })
255239
feedbackResult.deleted = deleted.length
256240
logger.info(`[${feedbackResult.table}] Deleted ${deleted.length} rows`)

apps/sim/lib/billing/cleanup-dispatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { sqlIsPaid, sqlIsPro, sqlIsTeam } from '@/lib/billing/plan-helpers'
77
import { ENTITLED_SUBSCRIPTION_STATUSES } from '@/lib/billing/subscriptions/utils'
88
import { getJobQueue } from '@/lib/core/async-jobs'
99
import { shouldExecuteInline } from '@/lib/core/async-jobs/config'
10+
import { toError } from '@/lib/core/utils/helpers'
1011
import { isTriggerAvailable } from '@/lib/knowledge/documents/service'
1112

1213
const logger = createLogger('RetentionDispatcher')
@@ -130,7 +131,7 @@ async function runInlineIfNeeded(
130131
await runner(payload)
131132
await jobQueue.completeJob(jobId, null)
132133
} catch (error) {
133-
const errorMessage = error instanceof Error ? error.message : String(error)
134+
const errorMessage = toError(error).message
134135
logger.error(`[${jobType}] Inline job ${jobId} failed`, { error: errorMessage })
135136
try {
136137
await jobQueue.markJobFailed(jobId, errorMessage)

packages/db/migrations/0193_unknown_franklin_richards.sql renamed to packages/db/migrations/0192_colossal_the_watchers.sql

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
CREATE TABLE "outbox_event" (
2-
"id" text PRIMARY KEY NOT NULL,
3-
"event_type" text NOT NULL,
4-
"payload" json NOT NULL,
5-
"status" text DEFAULT 'pending' NOT NULL,
6-
"attempts" integer DEFAULT 0 NOT NULL,
7-
"max_attempts" integer DEFAULT 10 NOT NULL,
8-
"available_at" timestamp DEFAULT now() NOT NULL,
9-
"locked_at" timestamp,
10-
"last_error" text,
11-
"created_at" timestamp DEFAULT now() NOT NULL,
12-
"processed_at" timestamp
13-
);
14-
--> statement-breakpoint
151
DROP INDEX "chat_archived_at_idx";--> statement-breakpoint
162
DROP INDEX "doc_archived_at_idx";--> statement-breakpoint
173
DROP INDEX "doc_deleted_at_idx";--> statement-breakpoint
@@ -22,13 +8,9 @@ DROP INDEX "mcp_servers_workspace_deleted_idx";--> statement-breakpoint
228
DROP INDEX "webhook_archived_at_idx";--> statement-breakpoint
239
DROP INDEX "workflow_mcp_tool_archived_at_idx";--> statement-breakpoint
2410
DROP INDEX "workflow_schedule_archived_at_idx";--> statement-breakpoint
25-
ALTER TABLE "user_stats" ADD COLUMN "pro_period_cost_snapshot_at" timestamp;--> statement-breakpoint
26-
ALTER TABLE "workspace" ADD COLUMN "logo_url" text;--> statement-breakpoint
2711
ALTER TABLE "workspace" ADD COLUMN "log_retention_hours" integer;--> statement-breakpoint
2812
ALTER TABLE "workspace" ADD COLUMN "soft_delete_retention_hours" integer;--> statement-breakpoint
2913
ALTER TABLE "workspace" ADD COLUMN "task_cleanup_hours" integer;--> statement-breakpoint
30-
CREATE INDEX "outbox_event_status_available_idx" ON "outbox_event" USING btree ("status","available_at");--> statement-breakpoint
31-
CREATE INDEX "outbox_event_locked_at_idx" ON "outbox_event" USING btree ("locked_at");--> statement-breakpoint
3214
CREATE INDEX "a2a_agent_workspace_archived_partial_idx" ON "a2a_agent" USING btree ("workspace_id","archived_at") WHERE "a2a_agent"."archived_at" IS NOT NULL;--> statement-breakpoint
3315
CREATE INDEX "chat_archived_at_partial_idx" ON "chat" USING btree ("archived_at") WHERE "chat"."archived_at" IS NOT NULL;--> statement-breakpoint
3416
CREATE INDEX "doc_archived_at_partial_idx" ON "document" USING btree ("archived_at") WHERE "document"."archived_at" IS NOT NULL;--> statement-breakpoint

0 commit comments

Comments
 (0)