Skip to content

fix(db): index cache_entries.locationId so storage cleanup stops locking SQLite - #266

Merged
LouisHaftmann merged 2 commits into
devfrom
fix/cache-entries-location-index
Sep 13, 2026
Merged

LouisHaftmann merged 2 commits into
devfrom
fix/cache-entries-location-index

Conversation

@LouisHaftmann

@LouisHaftmann LouisHaftmann commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

📝 Summary

cleanup:storage-locations looks for storage locations that no cache entry points to. cache_entries.locationId had no index, so for every storage location the query scanned the whole cache_entries table. With tens of thousands of rows on SQLite this ran for 30+ seconds, held up writes with SQLITE_BUSY, and caused health probe timeouts and pod restarts. A new migration adds the index, which turns each lookup into an index search.

📦 Changes

  • New migration $6_cache_entries_locationId_index that creates idx_cache_entries_locationId on cache_entries(locationId)
  • Down migrations now drop indexes with DROP INDEX ... ON table on MySQL, which requires it. The down steps of $2 and $3 were broken on MySQL before

✅ Verification

  • pnpm type-check: pass
  • pnpm lint: pass
  • pnpm build: pass
  • pnpm test:run (sqlite, postgres, mysql with filesystem storage): 41 passed, 2 skipped

🔍 Reviews

Review Found Fixed
code-review 2 1
ponytail-review 0 0

Not fixed: on MySQL, InnoDB may drop its implicit foreign key index once this index exists, so rolling back this migration could fail with error 1553. This only affects down. Nothing runs down migrations today, so I left it alone.

🔗 Issues

Closes #260

⚠️ Needs attention

  • The issue also suggests running cleanup:parts and cleanup:storage-locations one after the other instead of at the same time. This PR doesn't do that.

🤖 Generated with Claude Code

LouisHaftmann and others added 2 commits September 13, 2026 12:53
Closes #260

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@LouisHaftmann
LouisHaftmann merged commit 7582745 into dev Sep 13, 2026
24 checks passed
@LouisHaftmann
LouisHaftmann deleted the fix/cache-entries-location-index branch September 13, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite cleanup: missing cache_entries(locationId) index causes SQLITE_BUSY and liveness restarts

1 participant