Fixed qualities and other properties cleared on update.

This commit is contained in:
DebaucheryLibrarian
2026-11-23 21:45:04 +01:00
parent a184da7c8f
commit 4210153417
+21 -9
View File
@@ -457,22 +457,34 @@ async function storeScenes(releases, useBatchId) {
const updatedChunks = await Promise.all(chunk(curatedDuplicateReleases, 500).map(async (chunkedReleases) => knex.raw(`
UPDATE releases
SET url = COALESCE(new.url, releases.url),
-- new data overwrites, but an empty value from the scraper never clears a stored one
SET url = COALESCE(NULLIF(new.url, ''), releases.url),
date = COALESCE(new.date, releases.date),
entity_id = COALESCE((new.entity->>'id')::integer, releases.entity_id),
title = COALESCE(new.title, releases.title),
description = COALESCE(new.description, releases.description),
shoot_id = COALESCE(new.shoot_id, releases.shoot_id),
date_precision = CASE WHEN new.date IS NOT NULL THEN COALESCE(new.date_precision, releases.date_precision) ELSE releases.date_precision END,
entity_id = COALESCE(new.entity_id, releases.entity_id), -- i.e. a scene stored under the network moves to its channel, see filterDuplicateReleases
studio_id = COALESCE(new.studio_id, releases.studio_id),
title = COALESCE(NULLIF(new.title, ''), releases.title),
alt_titles = COALESCE(NULLIF(new.alt_titles, '{}'), releases.alt_titles),
description = COALESCE(NULLIF(new.description, ''), releases.description),
alt_descriptions = COALESCE(NULLIF(new.alt_descriptions, '{}'), releases.alt_descriptions),
shoot_id = COALESCE(NULLIF(new.shoot_id, ''), releases.shoot_id),
duration = COALESCE(new.duration, releases.duration),
qualities = COALESCE(NULLIF(new.qualities, '{}'), releases.qualities), -- curated as an empty array when the scraper provides none
photo_count = COALESCE(new.photo_count, releases.photo_count),
production_date = COALESCE(new.production_date, releases.production_date),
production_date_precision = COALESCE(new.production_date_precision, releases.production_date_precision),
production_date_precision = CASE WHEN new.production_date IS NOT NULL THEN COALESCE(new.production_date_precision, releases.production_date_precision) ELSE releases.production_date_precision END,
production_location = COALESCE(NULLIF(new.production_location, ''), releases.production_location),
production_city = COALESCE(NULLIF(new.production_city, ''), releases.production_city),
production_state = COALESCE(NULLIF(new.production_state, ''), releases.production_state),
production_country_alpha2 = COALESCE(NULLIF(new.production_country_alpha2, ''), releases.production_country_alpha2),
language_alpha2 = COALESCE(new.language_alpha2, releases.language_alpha2),
comment = COALESCE(new.comment, releases.comment),
attributes = COALESCE(new.attributes::jsonb || releases.attributes::jsonb, new.attributes::jsonb, releases.attributes::jsonb),
comment = COALESCE(NULLIF(new.comment, ''), releases.comment),
attributes = COALESCE(releases.attributes::jsonb || new.attributes::jsonb, new.attributes::jsonb, releases.attributes::jsonb), -- new keys overwrite stored ones
deep = new.url IS NOT NULL,
deep_url = COALESCE(NULLIF(new.deep_url, ''), releases.deep_url),
updated_at = NOW()
FROM json_to_recordset(:scenes)
AS new(id int, url text, date timestamptz, entity json, title text, description text, shoot_id text, duration integer, production_date timestamptz, production_date_precision text, language_alpha2 text, comment text, attributes json, deep boolean)
AS new(id int, url text, date timestamptz, date_precision text, entity_id integer, studio_id integer, title text, alt_titles text[], description text, alt_descriptions text[], shoot_id text, duration integer, qualities text[], photo_count integer, production_date timestamptz, production_date_precision text, production_location text, production_city text, production_state text, production_country_alpha2 text, language_alpha2 text, comment text, attributes json, deep boolean, deep_url text)
WHERE releases.id = new.id
RETURNING releases.*
`, {