Staged media flushing for improved feedback and performance.

This commit is contained in:
DebaucheryLibrarian 2025-02-27 01:21:32 +01:00
parent f3e82375ad
commit 1a34dbd76d
2 changed files with 7 additions and 1 deletions

View File

@ -447,6 +447,7 @@ module.exports = {
attempts: 2, attempts: 2,
fetchStreams: true, fetchStreams: true,
streamConcurrency: 2, // max number of video streams (m3u8 etc.) to fetch and process at once streamConcurrency: 2, // max number of video streams (m3u8 etc.) to fetch and process at once
flushWindow: 1000,
}, },
titleSlugLength: 50, titleSlugLength: 50,
}; };

View File

@ -1056,7 +1056,8 @@ async function flushOrphanedMedia() {
) )
.as('associations'), .as('associations'),
) )
.whereRaw('associations.media_id = media.id'), .whereRaw('associations.media_id = media.id')
.limit(config.media.flushWindow),
) )
.returning(['media.id', 'media.is_s3', 'media.path', 'media.thumbnail', 'media.lazy']) .returning(['media.id', 'media.is_s3', 'media.path', 'media.thumbnail', 'media.lazy'])
.delete(); .delete();
@ -1085,6 +1086,10 @@ async function flushOrphanedMedia() {
} catch (error) { } catch (error) {
logger.warn(`Failed to clear temporary media directory: ${error.message}`); logger.warn(`Failed to clear temporary media directory: ${error.message}`);
} }
if (orphanedMedia.length > 0 && orphanedMedia.length >= config.media.flushWindow) {
await flushOrphanedMedia();
}
} }
module.exports = { module.exports = {