Catching media failures per batch. Refined teaser logging.

This commit is contained in:
ThePendulum 2020-02-20 22:27:00 +01:00
parent 278246a343
commit 7ac5a8e08c
3 changed files with 53 additions and 44 deletions

View File

@ -43,7 +43,7 @@ body {
display: flex;
justify-content: center;
align-items: center;
padding: .5rem 0;
padding: .5rem .25rem;
font-weight: bold;
font-size: .9rem;
cursor: pointer;

View File

@ -231,6 +231,7 @@ function groupItems(items) {
}
async function storeMedia(sources, domain, role) {
try {
const presentSources = sources.filter(Boolean);
if (presentSources.length === 0) {
@ -269,6 +270,11 @@ async function storeMedia(sources, domain, role) {
logger.info(`Stored ${fetchedItems.length} new ${domain} ${role}s`);
return itemsBySource;
} catch (error) {
logger.error(`Failed to store ${domain} ${role} batch: ${error.message}`);
return null;
}
}
function extractPrimaryItem(associations, targetId, role, primaryRole, primaryItemsByTargetId) {
@ -302,7 +308,7 @@ function associateTargetMedia(targetId, sources, mediaBySource, domain, role, pr
})
.filter(Boolean);
logger.info(`Associating ${associations.length} ${role}s to ${domain} ${targetId}`);
logger.silly(`Associating ${associations.length} ${role}s to ${domain} ${targetId}`);
return extractPrimaryItem(associations, targetId, role, primaryRole, primaryItemsByTargetId);
}
@ -316,6 +322,9 @@ async function associateMedia(sourcesByTargetId, mediaBySource, domain, role, pr
const associations = associationsPerTarget.map(association => association[role]).flat().filter(Boolean);
const primaryAssociations = associationsPerTarget.map(association => association[primaryRole]).filter(Boolean);
logger.info(`Associated ${associations.length} ${role}s to ${domain}s`);
logger.info(`Associated ${primaryAssociations.length} extracted ${primaryRole}s to ${domain}s`);
return Promise.all([
(associations.length > 0 && knex.raw(`${knex(`${domain}s_${role}s`).insert(associations).toString()} ON CONFLICT DO NOTHING`)),
(primaryAssociations.length > 0 && knex.raw(`${knex(`${domain}s_${primaryRole}s`).insert(primaryAssociations).toString()} ON CONFLICT DO NOTHING`)),

View File

@ -346,12 +346,12 @@ async function storeReleaseAssets(releases) {
// ensure posters are available before fetching supplementary media
await Promise.all([
associateMedia(releasePostersById, posters, 'release', 'poster'),
associateMedia(releaseCoversById, covers, 'release', 'cover'),
(posters && associateMedia(releasePostersById, posters, 'release', 'poster')),
(covers && associateMedia(releaseCoversById, covers, 'release', 'cover')),
]);
// const photos = await storeMedia(Object.values(releasePhotosById).flat(), 'release', 'photo');
// await associateMedia(releasePhotosById, photos, 'release', 'photo');
const photos = await storeMedia(Object.values(releasePhotosById).flat(), 'release', 'photo');
if (photos) await associateMedia(releasePhotosById, photos, 'release', 'photo');
// videos take a long time, fetch last
const [trailers, teasers] = await Promise.all([
@ -360,8 +360,8 @@ async function storeReleaseAssets(releases) {
]);
await Promise.all([
associateMedia(releaseTrailersById, trailers, 'release', 'trailer'),
associateMedia(releaseTeasersById, teasers, 'release', 'teaser'),
(trailers && associateMedia(releaseTrailersById, trailers, 'release', 'trailer')),
(teasers && associateMedia(releaseTeasersById, teasers, 'release', 'teaser')),
]);
}