feat: import stage upserts to replace lower-quality library items

This commit is contained in:
Jonathan
2026-07-11 12:40:11 +02:00
parent 133f6219ae
commit 3934a0c45d
2 changed files with 45 additions and 1 deletions
+5 -1
View File
@@ -88,7 +88,11 @@ def _import(conn: psycopg.Connection, job_id: str, target: MBTarget,
'INSERT INTO "LibraryItem" (id, "requestId", artist, album, path, source, '
'format, "qualityClass", "importedAt") '
"VALUES (gen_random_uuid()::text, %s, %s, %s, %s, %s, %s, %s, now()) "
'ON CONFLICT (artist, album) DO NOTHING',
'ON CONFLICT (artist, album) DO UPDATE SET '
' "requestId" = EXCLUDED."requestId", path = EXCLUDED.path, source = EXCLUDED.source, '
' format = EXCLUDED.format, "qualityClass" = EXCLUDED."qualityClass", '
' "importedAt" = now() '
'WHERE EXCLUDED."qualityClass" > "LibraryItem"."qualityClass"',
(request_id, target.artist, target.album, path, winner.source,
winner.quality.fmt, quality_class(winner.quality)),
)