Chunked sync updates, worked around view dependency.

This commit is contained in:
2026-11-27 00:35:04 +01:00
parent de2aa49fc8
commit d080d82bb7
+15 -5
View File
@@ -130,10 +130,10 @@ export async function syncManticoreScenes(sceneIds) {
AND (parents.showcased IS NOT false OR COALESCE(entities.showcased, false) = true OR COALESCE(studios.showcased, false) = true)
AS showcased,
-- kept separate from the channel showcasing, a batch only hides large scrapes from New, not from Latest and Upcoming
releases_summaries.batch_showcased IS NOT false AS batch_showcased,
batches.showcased IS NOT false AS batch_showcased,
row_number() OVER (PARTITION BY releases.entry_id, parents.id ORDER BY releases.effective_date DESC) as dupe_index
FROM releases
LEFT JOIN releases_summaries ON releases_summaries.release_id = releases.id
LEFT JOIN batches ON batches.id = releases.updated_batch_id -- set when stored, a rescrape doesn't move a scene to its batch
LEFT JOIN scenes_meta ON scenes_meta.scene_id = releases.id
LEFT JOIN entities ON releases.entity_id = entities.id
LEFT JOIN entities AS parents ON parents.id = entities.parent_id
@@ -159,7 +159,7 @@ export async function syncManticoreScenes(sceneIds) {
releases.date,
releases.shoot_id,
scenes_meta.stashed,
releases_summaries.batch_showcased,
batches.showcased,
entities.id,
entities.name,
entities.slug,
@@ -292,9 +292,19 @@ export async function syncManticoreScenes(sceneIds) {
export async function syncScenes(releaseIds, { notify: shouldNotify = true } = {}) {
await knex.raw('REFRESH MATERIALIZED VIEW scenes_meta;');
await syncManticoreScenes(releaseIds);
// a large scrape can queue hundreds of thousands of scenes, index and notify them in chunks rather than in one huge query
// notify fetches the scenes with one binding per ID, which fails beyond Postgres' 65535 bindings, and the queue would retry it forever
// notifications are per scene, and e-mails are buffered separately, so chunking doesn't split anything up
await (releaseIds ? chunk(releaseIds, 5000) : [null]).reduce(async (chain, sceneIds) => {
await chain;
await syncManticoreScenes(sceneIds);
if (shouldNotify) {
if (shouldNotify && sceneIds) {
await notify(sceneIds);
}
}, Promise.resolve());
if (shouldNotify && !releaseIds) {
await notify(releaseIds);
}
}