⚡ Fix O(targets×runs) nested substring scan in deletion-reference validation #12
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/project-deletion-reference-check-complexity"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #11. The org-scoping fix got the queries in validateDeletionReferences down to one organization, but SL-data/BLF-data deletion previews still hung for minutes. Live debug instrumentation on Fanyu found the real cost: ~2,600 BOS targets × ~8,000 other runs (~30KB marshaled JSON each) = ~21M strings.Contains pair-wise scans over ~240MB of JSON, confirmed pegging the api pod at 1 full core for minutes.
Replaced the O(targets×runs) nested loop with a single combined regexp (RE2, linear in text length regardless of alternative count) scanned once per other-run, collecting referenced URIs into a set. Same exact-substring semantics as before — verified with a new test (TestProjectDeletionBlocksTargetReferencedByOtherRun) plus a local benchmark at SL-data's real scale: 241ms, down from a multi-minute hang.
Tests: go build ./..., go vet ./..., go test ./internal/api/... ./internal/store/... (all deletion tests pass, 75 pre-existing unrelated failures unchanged).
🤖 Generated with Claude Code