Repository navigation
fix(server): index artifact.test_id so deleting a large project fits the statement timeout - #131
Open
ciprian-hudl wants to merge 2 commits into
Open
ciprian-hudl wants to merge 2 commits into
ciprian-hudl wants to merge 2 commits into
Conversation
…the statement timeout artifact.test_id references test.id with ON DELETE CASCADE but had no index, so deleting a project (project -> run -> test -> artifact) scanned the whole artifact table once per deleted test row. Projects with tens of thousands of test rows ran past the 30s statement_timeout on every delete attempt; the same cascade runs for retention purges of old runs. Adds artifact_testId_idx (migration + Drizzle schema), and a test that a project delete cascades through a test-scoped attachment and that the index exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
artifact.test_idreferencestest.idwithON DELETE CASCADE, but has no index. Deleting a project cascadesproject → run → test → artifact, and for every deletedtestrow Postgres scans the wholeartifacttable for matchingtest_ids.On a self-hosted instance, a project with a few hundred runs of ~200 tests (tens of thousands of
testrows) ran past the server's 30 sstatement_timeouton every delete attempt (Failed query: delete from "project" where "project"."id" = $1), while small projects deleted in under a second. The same cascade runs when retention purges old runs.Fix
Add
artifact_testId_idxonartifact(test_id): a migration following20260814180000_add_artifact_project_index, plus the matching index in the Drizzle schema.Tests
project-routertest: a project delete cascades through a test-scoped attachment (artifact.test_idset), andartifact_testId_idxexists after migrations. It fails without the migration.pnpm lint,pnpm typecheck,pnpm testpass; server integration tests pass against Postgres 18 and the S3 mock (282/283 locally.🤖 Generated with Claude Code