Repository navigation
fix(metadata): re-fetch titles/overviews when a library's metadata language changes - #278
Conversation
…nguage changes An item's default_metadata_language was stamped once at first match and never updated: the canonical-language pin in mergeAndPersist routed any refresh in a different language into the localization tables, the upserts' COALESCE kept the old stamp forever, quick-mode library refresh skipped complete items entirely, and changing the language in HandleUpdateLibrary triggered nothing. Items stayed in the old language no matter how often the admin refreshed (Silo-Server#211). Four coupled changes: - ProcessRequest.AdoptLanguage: folder-scoped manual refreshes adopt the library's language as the item's new canonical language when it differs from the stamp, rewriting the base row instead of localizing to the side. Only ModeManualRefresh adopts — scheduled refreshes merge fill-empty and would restamp without rewriting the text. - Upsert language pins inverted (media_items, seasons, episodes): prefer the incoming non-empty default_metadata_language over the existing stamp. All existing callers send the unchanged stamp or empty, so behavior is unchanged outside adoption; the restamp is atomic with the canonical write. - Quick-mode refresh lister now includes complete items whose stamp differs from the library's configured language. - HandleUpdateLibrary enqueues a quick library metadata refresh when the metadata language changes, mirroring the paths-change rescan trigger. Fixes Silo-Server#211 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change addresses issue ChangesLanguage adoption and refresh flow
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant HandleUpdateLibrary
participant JobRepo
participant EventBus
participant MetadataService
participant ItemRepository
Client->>HandleUpdateLibrary: PUT update library (new metadata_language)
HandleUpdateLibrary->>HandleUpdateLibrary: compare old vs new metadata_language
alt language changed
HandleUpdateLibrary->>JobRepo: CreateLibraryRefresh(quick mode)
JobRepo-->>HandleUpdateLibrary: success or active-job conflict
HandleUpdateLibrary->>EventBus: publish job.created (on success)
end
Client->>MetadataService: Process(ProcessRequest, ModeManualRefresh)
MetadataService->>MetadataService: adoptableFolderLanguage(item stamp, folder language)
MetadataService->>MetadataService: set AdoptLanguage on request
MetadataService->>ItemRepository: mergeAndPersist rewritten title/overview + restamped language
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/api/handlers/libraries.go (1)
619-727: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting the language-change trigger into a helper.
HandleUpdateLibrarynow handles validation, persistence, section-title sync, language-change refresh queuing, and path-change rescanning in one function. Not blocking, but a small helper (e.g.queueRefreshOnLanguageChange) would keep the handler focused as more triggers get added here.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handlers/libraries.go` around lines 619 - 727, HandleUpdateLibrary is getting too crowded with post-update side effects, so extract the metadata-language change refresh logic into a small helper to keep the handler focused. Move the `JobRepo.CreateLibraryRefresh` and related conflict/warn handling into a helper such as `queueRefreshOnLanguageChange`, and call it from `HandleUpdateLibrary` near the existing oldFolder/folder comparison. Keep the section-title sync and path-rescan logic in the handler for now, but make the language-change trigger self-contained for easier future expansion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/metadata/service.go`:
- Around line 520-534: Gate the extra item lookup in service.go’s folder-scoped
adoption block so it only runs for ModeManualRefresh before calling
s.itemRepo.GetByID, and keep the adoptableFolderLanguage check as the final
validation. Also stop swallowing GetByID failures silently: if the lookup
returns an error, log or otherwise surface it so adoption failures are visible
instead of silently no-oping.
---
Nitpick comments:
In `@internal/api/handlers/libraries.go`:
- Around line 619-727: HandleUpdateLibrary is getting too crowded with
post-update side effects, so extract the metadata-language change refresh logic
into a small helper to keep the handler focused. Move the
`JobRepo.CreateLibraryRefresh` and related conflict/warn handling into a helper
such as `queueRefreshOnLanguageChange`, and call it from `HandleUpdateLibrary`
near the existing oldFolder/folder comparison. Keep the section-title sync and
path-rescan logic in the handler for now, but make the language-change trigger
self-contained for easier future expansion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c78e3aa3-0a01-4c11-841c-db04c19e0cb5
📒 Files selected for processing (11)
internal/adminjob/library_refresh.gointernal/adminjob/library_refresh_language_test.gointernal/api/handlers/libraries.gointernal/api/handlers/libraries_language_change_test.gointernal/catalog/default_language_restamp_test.gointernal/catalog/episode_repo.gointernal/catalog/item_repo.gointernal/catalog/season_repo.gointernal/metadata/relanguage_test.gointernal/metadata/service.gointernal/metadata/types.go
| // A folder-scoped manual refresh resolves exactly one language — the | ||
| // library's setting. When that differs from the item's stamped canonical | ||
| // language, adopt it so the base row is re-fetched in the library's | ||
| // language instead of the fetch being shunted into localization tables | ||
| // forever (issue #211). Adoption is decided here (not in mergeAndPersist) | ||
| // so identify/initial-match and multi-language item-scoped refreshes are | ||
| // never affected. | ||
| adoptTarget := "" | ||
| if folderID > 0 && req.ContentID != "" && len(languages) == 1 && s.itemRepo != nil { | ||
| if item, err := s.itemRepo.GetByID(ctx, req.ContentID); err == nil && item != nil { | ||
| if adoptableFolderLanguage(req.Mode, item.DefaultMetadataLanguage, languages[0]) { | ||
| adoptTarget = languages[0] | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Gate the extra GetByID call on ModeManualRefresh before querying.
adoptableFolderLanguage immediately rejects any mode other than ModeManualRefresh, but the guard here doesn't check req.Mode before issuing s.itemRepo.GetByID. Every folder-scoped, single-language refresh — including ModeScheduledRefresh, which runs across whole libraries — now pays for an extra DB round trip that's discarded as soon as adoptableFolderLanguage checks the mode. mergeAndPersist already fetches the existing item separately for its own merge logic, so this is pure waste for non-manual modes.
Also, the GetByID error is silently swallowed (err == nil && item != nil), so transient failures cause the intended relanguage adoption to silently no-op with no trace.
🚀 Proposed fix
adoptTarget := ""
- if folderID > 0 && req.ContentID != "" && len(languages) == 1 && s.itemRepo != nil {
- if item, err := s.itemRepo.GetByID(ctx, req.ContentID); err == nil && item != nil {
- if adoptableFolderLanguage(req.Mode, item.DefaultMetadataLanguage, languages[0]) {
- adoptTarget = languages[0]
- }
- }
- }
+ if req.Mode == ModeManualRefresh && folderID > 0 && req.ContentID != "" && len(languages) == 1 && s.itemRepo != nil {
+ item, err := s.itemRepo.GetByID(ctx, req.ContentID)
+ if err != nil {
+ slog.Warn("metadata: loading item for language adoption check failed", "content_id", req.ContentID, "error", err)
+ } else if item != nil && adoptableFolderLanguage(req.Mode, item.DefaultMetadataLanguage, languages[0]) {
+ adoptTarget = languages[0]
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // A folder-scoped manual refresh resolves exactly one language — the | |
| // library's setting. When that differs from the item's stamped canonical | |
| // language, adopt it so the base row is re-fetched in the library's | |
| // language instead of the fetch being shunted into localization tables | |
| // forever (issue #211). Adoption is decided here (not in mergeAndPersist) | |
| // so identify/initial-match and multi-language item-scoped refreshes are | |
| // never affected. | |
| adoptTarget := "" | |
| if folderID > 0 && req.ContentID != "" && len(languages) == 1 && s.itemRepo != nil { | |
| if item, err := s.itemRepo.GetByID(ctx, req.ContentID); err == nil && item != nil { | |
| if adoptableFolderLanguage(req.Mode, item.DefaultMetadataLanguage, languages[0]) { | |
| adoptTarget = languages[0] | |
| } | |
| } | |
| } | |
| // A folder-scoped manual refresh resolves exactly one language — the | |
| // library's setting. When that differs from the item's stamped canonical | |
| // language, adopt it so the base row is re-fetched in the library's | |
| // language instead of the fetch being shunted into localization tables | |
| // forever (issue `#211`). Adoption is decided here (not in mergeAndPersist) | |
| // so identify/initial-match and multi-language item-scoped refreshes are | |
| // never affected. | |
| adoptTarget := "" | |
| if req.Mode == ModeManualRefresh && folderID > 0 && req.ContentID != "" && len(languages) == 1 && s.itemRepo != nil { | |
| item, err := s.itemRepo.GetByID(ctx, req.ContentID) | |
| if err != nil { | |
| slog.Warn("metadata: loading item for language adoption check failed", "content_id", req.ContentID, "error", err) | |
| } else if item != nil && adoptableFolderLanguage(req.Mode, item.DefaultMetadataLanguage, languages[0]) { | |
| adoptTarget = languages[0] | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/metadata/service.go` around lines 520 - 534, Gate the extra item
lookup in service.go’s folder-scoped adoption block so it only runs for
ModeManualRefresh before calling s.itemRepo.GetByID, and keep the
adoptableFolderLanguage check as the final validation. Also stop swallowing
GetByID failures silently: if the lookup returns an error, log or otherwise
surface it so adoption failures are visible instead of silently no-oping.
Code reviewFound 2 issues:
silo-server/internal/metadata/service.go Lines 1509 to 1516 in d4e8a1a
silo-server/internal/metadata/service.go Lines 528 to 541 in d4e8a1a Also noting (minor, likely acceptable scoping): The COALESCE inversions checked out: applied consistently across all three repos, no historical fix is being reverted (the old direction dates to the initial migration), and every existing caller sends either the unchanged stamp or empty, matching the commit message's claim. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
…ement Two hardening fixes for AdoptLanguage from review of Silo-Server#278: - Locked fields defeat the restamp: title/overview merges honor per-field locks, but the restamp was unconditional. An item with both language- bearing fields locked kept its old-language text yet got stamped the new language, so the quick-refresh mismatch predicate never flagged it again. mergeAndPersist now skips adoption when both name and overview are locked, falling back to the non-adopting behavior: the stamp stays put, isCanonicalWrite goes false, and the fetch routes to the localization tables exactly like a non-adopting refresh in that language does today. One locked field still adopts — the other is actually rewritten. - Multi-library flip-flop: an item in libraries with different metadata languages had its canonical base row rewritten to whichever library refreshed last, oscillating forever. Process now requires every library containing the item (media_item_libraries) to resolve to the adoption target before setting AdoptLanguage, via the existing GetDistinctMetadataLanguagesForItem (which applies the same empty→en default as resolveFolderLanguage). Disagreement or a lookup failure keeps the current stamp — stable beats flip-flopping. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Addressed both review findings in 4dbf2f3:
New tests cover both-locked (stamp unchanged), title-only-locked (stamp adopted, locked title preserved), and a table test for the agreement gate. All metadata/adminjob/catalog tests pass, including the DB-backed restamp tests against a real migrated scratch Postgres. 🤖 Generated with Claude Code |
…nguage changes (Silo-Server#278) * fix(metadata): re-fetch titles/overviews when a library's metadata language changes An item's default_metadata_language was stamped once at first match and never updated: the canonical-language pin in mergeAndPersist routed any refresh in a different language into the localization tables, the upserts' COALESCE kept the old stamp forever, quick-mode library refresh skipped complete items entirely, and changing the language in HandleUpdateLibrary triggered nothing. Items stayed in the old language no matter how often the admin refreshed (Silo-Server#211). Four coupled changes: - ProcessRequest.AdoptLanguage: folder-scoped manual refreshes adopt the library's language as the item's new canonical language when it differs from the stamp, rewriting the base row instead of localizing to the side. Only ModeManualRefresh adopts — scheduled refreshes merge fill-empty and would restamp without rewriting the text. - Upsert language pins inverted (media_items, seasons, episodes): prefer the incoming non-empty default_metadata_language over the existing stamp. All existing callers send the unchanged stamp or empty, so behavior is unchanged outside adoption; the restamp is atomic with the canonical write. - Quick-mode refresh lister now includes complete items whose stamp differs from the library's configured language. - HandleUpdateLibrary enqueues a quick library metadata refresh when the metadata language changes, mirroring the paths-change rescan trigger. Fixes Silo-Server#211 Co-Authored-By: Claude Fable 5 <[email protected]> * fix(metadata): gate language adoption on field locks and library agreement Two hardening fixes for AdoptLanguage from review of Silo-Server#278: - Locked fields defeat the restamp: title/overview merges honor per-field locks, but the restamp was unconditional. An item with both language- bearing fields locked kept its old-language text yet got stamped the new language, so the quick-refresh mismatch predicate never flagged it again. mergeAndPersist now skips adoption when both name and overview are locked, falling back to the non-adopting behavior: the stamp stays put, isCanonicalWrite goes false, and the fetch routes to the localization tables exactly like a non-adopting refresh in that language does today. One locked field still adopts — the other is actually rewritten. - Multi-library flip-flop: an item in libraries with different metadata languages had its canonical base row rewritten to whichever library refreshed last, oscillating forever. Process now requires every library containing the item (media_item_libraries) to resolve to the adoption target before setting AdoptLanguage, via the existing GetDistinctMetadataLanguagesForItem (which applies the same empty→en default as resolveFolderLanguage). Disagreement or a lookup failure keeps the current stamp — stable beats flip-flopping. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Quick <[email protected]>
Problem
An item's
default_metadata_languagewas stamped once at first match and never updated. Changing a library's metadata language did nothing for existing items: the canonical-language pin inmergeAndPersistrouted any refresh in a different language into the localization side-tables, the upserts'COALESCEkept the old stamp forever, quick-mode library refresh skipped complete items entirely, andHandleUpdateLibrarytriggered nothing on a language change. Items stayed in the old language no matter how often the admin refreshed or re-matched (#211).Approach — four coupled changes
HandleUpdateLibraryenqueues a quick library metadata refresh when the metadata language changes (mirrors the existing paths-change rescan trigger; conflict with an already-queued refresh is tolerated).ProcessRequest.AdoptLanguage;mergeAndPersistthen treats the library language as the new canonical — base-row title/overview are rewritten and the item restamped — instead of shunting the fetch into localization tables. Gated toModeManualRefreshonly: scheduled refreshes merge fill-empty and would restamp the language without rewriting the text.COALESCEclauses that madedefault_metadata_languagewrite-once (media_items, seasons ×2, episodes ×2) now prefer the incoming non-empty value. Every existing caller sends the unchanged stamp or an empty string, so behavior is unchanged outside adoption — and the restamp is atomic with the successful canonical write (no mislabeled rows if a provider fetch fails mid-refresh).Viewers preferring the old language still get localized text via the existing
LocalizeItemModeloverlay; the base row simply follows the library setting — which is what the setting claims to mean.Testing
SILO_TEST_DATABASE_URL) proving the upsert restamp semantics on all three tables and the quick-lister language-mismatch predicate.default_metadata_languagefollowed each change; this exact flow was a no-op before the fix).Risks / notes
ProcessRequestgains a field — additive, internal type.Fixes #211
AI-use disclosure
Implemented with Claude Code (test-first, live-validated); human-reviewed before submission.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes