Improved upcoming update query.
This commit is contained in:
@@ -323,25 +323,21 @@ async function storeScenes(releases) {
|
||||
const duplicateReleasesWithId = attachReleaseIds(duplicateReleases, duplicateReleaseEntries);
|
||||
const releasesWithId = uniqueReleasesWithId.concat(duplicateReleasesWithId);
|
||||
|
||||
try {
|
||||
await knex.raw(`
|
||||
UPDATE releases
|
||||
SET url = COALESCE(new.url, releases.url),
|
||||
date = COALESCE(new.date, releases.date),
|
||||
title = COALESCE(new.title, releases.title),
|
||||
description = COALESCE(new.description, releases.description),
|
||||
duration = COALESCE(new.duration, releases.duration),
|
||||
deep = new.url IS NOT NULL,
|
||||
updated_at = NOW()
|
||||
FROM json_to_recordset(:scenes)
|
||||
AS new(id int, url text, date timestamptz, title text, description text, duration integer, deep boolean)
|
||||
WHERE releases.id = new.id;
|
||||
`, {
|
||||
scenes: JSON.stringify(duplicateReleasesWithId),
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
const updated = await knex.raw(`
|
||||
UPDATE releases
|
||||
SET url = COALESCE(new.url, releases.url),
|
||||
date = COALESCE(new.date, releases.date),
|
||||
title = COALESCE(new.title, releases.title),
|
||||
description = COALESCE(new.description, releases.description),
|
||||
duration = COALESCE(new.duration, releases.duration),
|
||||
deep = new.url IS NOT NULL,
|
||||
updated_at = NOW()
|
||||
FROM json_to_recordset(:scenes)
|
||||
AS new(id int, url text, date timestamptz, title text, description text, duration integer, deep boolean)
|
||||
WHERE releases.id = new.id;
|
||||
`, {
|
||||
scenes: JSON.stringify(duplicateReleasesWithId),
|
||||
});
|
||||
|
||||
const [actors] = await Promise.all([
|
||||
associateActors(releasesWithId, batchId),
|
||||
@@ -359,7 +355,7 @@ async function storeScenes(releases) {
|
||||
await scrapeActors(actors.map(actor => actor.name));
|
||||
}
|
||||
|
||||
logger.info(`Stored ${storedReleaseEntries.length} releases`);
|
||||
logger.info(`Stored ${storedReleaseEntries.length}, updated ${updated.rowCount} releases`);
|
||||
|
||||
await notify(releasesWithId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user