* 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 (#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 #211 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(metadata): gate language adoption on field locks and library agreement Two hardening fixes for AdoptLanguage from review of #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 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Quick <31828688+Quick104@users.noreply.github.com>
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package adminjob
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// TestQuickRefreshListsLanguageMismatchedItems covers the listing half of
|
|
// issue #211: quick-mode library refresh must include items whose stamped
|
|
// default_metadata_language differs from the library's configured metadata
|
|
// language, even when the item is otherwise complete (overview, poster,
|
|
// backdrop all present) — otherwise a library language change never revisits
|
|
// already-complete items.
|
|
func TestQuickRefreshListsLanguageMismatchedItems(t *testing.T) {
|
|
dsn := os.Getenv("SILO_TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("SILO_TEST_DATABASE_URL is not set")
|
|
}
|
|
ctx := context.Background()
|
|
pool, err := pgxpool.New(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatalf("connect test database: %v", err)
|
|
}
|
|
t.Cleanup(pool.Close)
|
|
|
|
suffix := time.Now().UnixNano()
|
|
mismatchID := fmt.Sprintf("lang-mismatch-%d", suffix)
|
|
matchedID := fmt.Sprintf("lang-matched-%d", suffix)
|
|
|
|
var folderID int
|
|
if err := pool.QueryRow(ctx, `
|
|
INSERT INTO media_folders (type, name, enabled, metadata_language)
|
|
VALUES ('movies', 'Lang Refresh Test', true, 'da')
|
|
RETURNING id
|
|
`).Scan(&folderID); err != nil {
|
|
t.Fatalf("seed folder: %v", err)
|
|
}
|
|
t.Cleanup(func() {
|
|
_, _ = pool.Exec(ctx, `DELETE FROM media_items WHERE content_id = ANY($1)`, []string{mismatchID, matchedID})
|
|
_, _ = pool.Exec(ctx, `DELETE FROM media_folders WHERE id = $1`, folderID)
|
|
})
|
|
|
|
for _, row := range []struct {
|
|
id, lang string
|
|
}{
|
|
{mismatchID, "zh"},
|
|
{matchedID, "da"},
|
|
} {
|
|
if _, err := pool.Exec(ctx, `
|
|
INSERT INTO media_items (
|
|
content_id, type, title, status, genres, tmdb_id,
|
|
default_metadata_language, overview, poster_path, backdrop_path,
|
|
last_refreshed, refresh_failures, episode_metadata_incomplete
|
|
) VALUES ($1, 'movie', 'Complete Item', 'matched', '{}'::text[], '42',
|
|
$2, 'An overview', '/p.jpg', '/b.jpg', NOW(), 0, FALSE)
|
|
`, row.id, row.lang); err != nil {
|
|
t.Fatalf("seed media item %s: %v", row.id, err)
|
|
}
|
|
if _, err := pool.Exec(ctx, `
|
|
INSERT INTO media_item_libraries (content_id, media_folder_id)
|
|
VALUES ($1, $2)
|
|
`, row.id, folderID); err != nil {
|
|
t.Fatalf("link media item %s: %v", row.id, err)
|
|
}
|
|
}
|
|
|
|
lister := NewPGLibraryRefreshItemLister(pool)
|
|
items, err := lister.ListLibraryItems(ctx, folderID, LibraryRefreshModeQuick)
|
|
if err != nil {
|
|
t.Fatalf("ListLibraryItems: %v", err)
|
|
}
|
|
|
|
var sawMismatch, sawMatched bool
|
|
for _, item := range items {
|
|
switch item.ContentID {
|
|
case mismatchID:
|
|
sawMismatch = true
|
|
case matchedID:
|
|
sawMatched = true
|
|
}
|
|
}
|
|
if !sawMismatch {
|
|
t.Errorf("quick refresh must include complete item with stamped language differing from the library language")
|
|
}
|
|
if sawMatched {
|
|
t.Errorf("quick refresh must not include complete item whose stamped language matches the library language")
|
|
}
|
|
}
|