feat: import stage upserts to replace lower-quality library items
This commit is contained in:
@@ -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)),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user