Skip to content

Commit 80d4819

Browse files
authored
fix(webapp): stop slow database cleanup on project deletion (#4191)
## Summary Deleting a project triggered an unbounded database cleanup that scanned the project's entire run history, so deleting a project with many runs could be very slow. Project deletion is a soft delete again: run data is retained and the deletion completes quickly. ## Fix Project deletion ran a cascade hard-delete whose `BulkActionItem` step filtered through a relation to `TaskRun` scoped by `projectId`. Prisma compiles that to an `EXISTS`-join over the project's entire `TaskRun` set (a large, hot table with no `projectId` index), and it ran on every project deletion unconditionally. Removing the cascade-cleanup call restores the prior soft-delete behaviour: queues are removed, the project is marked deleted, and run data is retained. The cascade-cleanup service (added in [#4117](#4117)) had no other callers, so it and its test are deleted.
1 parent a682f1d commit 80d4819

5 files changed

Lines changed: 9 additions & 941 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Deleting a project no longer triggers a slow database cleanup that could hang on projects with many runs.

apps/webapp/app/services/archiveBranch.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export class ArchiveBranchService {
8282
}
8383

8484
// Branch archive is a SOFT update — do NOT hard-delete run-ops rows here (it would destroy a
85-
// retained branch's history). RunOpsCascadeCleanupService.cleanupEnvironment belongs on the
86-
// env hard-delete/purge path (owned by the cloud env-purge runbook), which has no site today.
85+
// retained branch's history). Any env hard-delete/purge belongs on a dedicated purge path
86+
// (owned by the cloud env-purge runbook), which has no site today.
8787
const slug = `${environment.slug}-${nanoid(6)}`;
8888
const shortcode = slug;
8989

apps/webapp/app/services/deleteProject.server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { prisma } from "~/db.server";
33
import { marqs } from "~/v3/marqs/index.server";
44
import { engine } from "~/v3/runEngine.server";
55
import { controlPlaneResolver } from "~/v3/runOpsMigration/controlPlaneResolver.server";
6-
import { RunOpsCascadeCleanupService } from "~/v3/runOpsMigration/runOpsCascadeCleanup.server";
76

87
type Options = ({ projectId: string } | { projectSlug: string }) & {
98
userId: string;
@@ -51,9 +50,7 @@ export class DeleteProjectService {
5150
});
5251
}
5352

54-
// Hard-delete the project's run-ops rows across both run-ops DBs (replaces the cloud-only
55-
// dropped cross-seam FK cascades). Idempotent; uses the run-ops writers, not #prismaClient.
56-
await new RunOpsCascadeCleanupService().cleanupProject(project.id);
53+
// Soft delete only: run-ops rows are intentionally retained (no hard-delete cascade here).
5754

5855
// Mark the project as deleted (do this last because it makes it impossible to try again)
5956
// - This disables all API keys

apps/webapp/app/v3/runOpsMigration/runOpsCascadeCleanup.server.ts

Lines changed: 0 additions & 275 deletions
This file was deleted.

0 commit comments

Comments
 (0)