From 1a34dbd76d91f37554f009b3335b4fb1f13986a4 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 27 Feb 2025 01:21:32 +0100 Subject: [PATCH] Staged media flushing for improved feedback and performance. --- config/default.js | 1 + src/media.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/default.js b/config/default.js index 2c83545b..f9118207 100755 --- a/config/default.js +++ b/config/default.js @@ -447,6 +447,7 @@ module.exports = { attempts: 2, fetchStreams: true, streamConcurrency: 2, // max number of video streams (m3u8 etc.) to fetch and process at once + flushWindow: 1000, }, titleSlugLength: 50, }; diff --git a/src/media.js b/src/media.js index f1ca7dde..f4c02bad 100755 --- a/src/media.js +++ b/src/media.js @@ -1056,7 +1056,8 @@ async function flushOrphanedMedia() { ) .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']) .delete(); @@ -1085,6 +1086,10 @@ async function flushOrphanedMedia() { } catch (error) { logger.warn(`Failed to clear temporary media directory: ${error.message}`); } + + if (orphanedMedia.length > 0 && orphanedMedia.length >= config.media.flushWindow) { + await flushOrphanedMedia(); + } } module.exports = {