Repository navigation
fix(scanner): scope file reconciliation to changed path - #741
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: 5 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour. 📝 WalkthroughWalkthroughSingle-file scans now repair catalog memberships for only the affected media file. The change also restores episode links and timestamps. A database-backed integration test verifies target restoration, unrelated-item isolation, and timestamp updates. ChangesPresent-file reconciliation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change limits file-scoped reconciliation to the changed path while preserving per-file repairs and existing folder-wide cleanup where required; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Review follow-ups for the file-scoped reconciliation: - Collapse syncPresentLibraryState and syncPresentFileState into one syncPresentState implementation with an optional exact-path scope, so the two variants cannot drift. The folder-wide entry point emits the same SQL as before; the episode-membership statement is unified on the sibling-join shape so first_seen_at always aggregates over all of an episode's active files. - Run the four repair statements in a single transaction instead of four autocommit round-trips, so a crash mid-repair cannot leave a row with its links cleared but its memberships unrestored. - Remove the syncPresentFileState call in the extras-conversion branch: the preceding Upsert already nulls the row's content/episode links, making every statement a no-op there. The membership cleanup at that site comes from the unchanged reconcileLibraryMemberships call. - Drop the redundant COALESCE inside GREATEST in the series denorm bump. - Extend the regression test to drive both scopes through the unified body, including dangling content link repair. Co-Authored-By: Claude Fable 5 <[email protected]>
Problem
Related issue: N/A — narrow fix
A file-scoped Autoscan request ended by calling
syncPresentLibraryState, which reconciles every catalog membership in the media folder. On a large production library, the plans scanned mostmedia_filesrows and millions ofepisodesrows for each changed file. Bursts of subtitle sidecar updates therefore kept PostgreSQL busy with folder-wide work even though each request named one path.Approach
Both scopes now share one implementation,
syncPresentState(ctx, folderID, filePath *string):syncPresentLibraryStateandsyncPresentFileStateare thin wrappers, and the exact-path predicate is appended in Go so the folder-wide plan is unchanged. The repair performs, in a single transaction:ON DELETE SET NULLFK, so that statement is defensive);first_seen_atover all of the episode's active files rather than just the scanned path;latest_episode_added_atonly for genuinely new links.The transaction replaces four autocommit round-trips, so a crash mid-repair can no longer leave a row with its links cleared but its memberships unrestored.
The extras-conversion branch no longer calls the sync at all: the
Upsertthat converts a row into an extra already nulls its content/episode links, which made every statement of the sync a no-op there. The membership cleanup on that path comes from the unchanged folder-widereconcileLibraryMembershipscall. (An earlier revision of this PR kept a file-scoped sync call there and described it as retaining cleanup; review showed it was dead code.)Validation
Passed:
go test ./internal/scanner ./internal/autoscan ./internal/libraryingest -count=1go test ./internal/scanner -count=1withSILO_TEST_DATABASE_URLagainst a local migrated Postgres — the DB-backed regression tests executed (not skipped), covering the file scope, the folder-wide scope through the same unified body, and dangling content-link repair in both scopesgo build ./...go vet ./...gofmt -l .(no output)pnpm install --frozen-lockfilepnpm run lint(0 errors; 155 existing warnings)pnpm run format:checkpnpm run build(existing font and chunk-size warnings)make test-web(283 files, 2,039 tests)make verify-settings-bindings-allmake verify-playback-fixturesmake verify-local-pathsmake test-goran the full suite. All scanner tests passed, but the command failed on two unrelated macOS Jellycompat process-lock tests:TestBeginWebOperationRecoversDeadProcessLockTestBeginWebOperationRejectsLiveProcessLockThe same path was exercised on shared-dev through a real file scan: the scan completed in 2.07 seconds, and
EXPLAIN ANALYZEused the exact-path and active-episode indexes with 3.19 ms execution time and no broad sequential scan. During CephFS batches of 33 and 37 file scans, PostgreSQL sampled at 0.67–2.23% CPU; health and readiness remained green.golangci-lint run --new-from-merge-base="origin/main" ./...was not run becausegolangci-lintis not installed in this environment.Risks
A single-file scan no longer repairs unrelated stale memberships in the same folder. Full folder scans retain that cleanup, and the extra-conversion path still runs
reconcileLibraryMemberships. There are no migrations or API changes.Pre-existing and unchanged by this PR: the plain single-file scan path never deletes a stale membership left behind when a file is re-identified from one content ID to another (neither sync variant issues DELETEs; that cleanup belongs to
reconcileLibraryMemberships, which the plain path does not call). Worth a follow-up issue.AI Disclosure
Checklist