Catching media storage errors to prevent full crash.

This commit is contained in:
DebaucheryLibrarian 2021-02-05 03:37:04 +01:00
parent c9b774c498
commit 688863d16e
1 changed files with 23 additions and 19 deletions

View File

@ -731,29 +731,33 @@ async function associateReleaseMedia(releases, type = 'release') {
return;
}
const storedMedias = await storeMedias(baseMedias);
const storedMediasById = itemsByKey(storedMedias, 'id');
try {
const storedMedias = await storeMedias(baseMedias);
const storedMediasById = itemsByKey(storedMedias, 'id');
const associations = Object
.entries(baseMediasByReleaseId)
.reduce((acc, [releaseId, releaseBaseMedias]) => {
releaseBaseMedias.forEach((baseMedia) => {
const media = storedMediasById[baseMedia.id];
const associations = Object
.entries(baseMediasByReleaseId)
.reduce((acc, [releaseId, releaseBaseMedias]) => {
releaseBaseMedias.forEach((baseMedia) => {
const media = storedMediasById[baseMedia.id];
if (media) {
acc.push({
[`${type}_id`]: releaseId,
media_id: media.use || media.entry.id,
});
}
});
if (media) {
acc.push({
[`${type}_id`]: releaseId,
media_id: media.use || media.entry.id,
});
}
});
return acc;
}, [])
.filter(Boolean);
return acc;
}, [])
.filter(Boolean);
if (associations.length > 0) {
await bulkInsert(`${type}s_${role}`, associations, false);
if (associations.length > 0) {
await bulkInsert(`${type}s_${role}`, associations, false);
}
} catch (error) {
logger.error(`Failed to store ${type} ${role}: ${error.message}`);
}
}, Promise.resolve());
}