From 92d8ccd257c6457fb990f68652afdec1c792a7eb Mon Sep 17 00:00:00 2001 From: Dispatcharr Date: Fri, 10 Oct 2025 14:24:22 -0500 Subject: [PATCH] ytre --- apps/media_library/tasks.py | 1 + .../components/library/LibraryScanDrawer.jsx | 35 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/media_library/tasks.py b/apps/media_library/tasks.py index 54815297..47eeaca8 100644 --- a/apps/media_library/tasks.py +++ b/apps/media_library/tasks.py @@ -424,6 +424,7 @@ def scan_library_task( for file_id in sorted(pending_probe_ids): probe_media_task.apply_async(args=(file_id,), **options) probes_scheduled = True + pending_probe_ids.clear() def refresh_stage_counters() -> None: nonlocal metadata_total_count, metadata_processed_count, artwork_total_count, artwork_processed_count diff --git a/frontend/src/components/library/LibraryScanDrawer.jsx b/frontend/src/components/library/LibraryScanDrawer.jsx index 71bd42ad..3563ea17 100644 --- a/frontend/src/components/library/LibraryScanDrawer.jsx +++ b/frontend/src/components/library/LibraryScanDrawer.jsx @@ -68,6 +68,9 @@ const stageColorMap = { artwork: 'red', }; +const PROGRESS_REFRESH_DELTA = 25; +const PROGRESS_REFRESH_INTERVAL_MS = 15000; + const LibraryScanDrawer = ({ opened, onClose, @@ -89,6 +92,7 @@ const LibraryScanDrawer = ({ const hasQueuedRef = useRef(false); const lastProcessedRef = useRef(0); const lastLibraryRefreshRef = useRef(0); + const refreshInFlightRef = useRef(false); const handleRefresh = useCallback( () => fetchScans(libraryId), @@ -170,28 +174,37 @@ const LibraryScanDrawer = ({ useEffect(() => { if (!opened) return; + + if (!hasRunningScan && !hasQueuedScan) { + lastProcessedRef.current = totalProcessed; + return; + } + const now = Date.now(); const prevProcessed = lastProcessedRef.current; - const shouldRefreshLibrary = - (hasRunningScan || hasQueuedScan) && - (totalProcessed > prevProcessed || - now - lastLibraryRefreshRef.current > 15000); + const processedDelta = Math.max(0, totalProcessed - prevProcessed); + const elapsedSinceRefresh = now - lastLibraryRefreshRef.current; - if (!shouldRefreshLibrary) { - if (totalProcessed > prevProcessed) { - lastProcessedRef.current = totalProcessed; - } + const shouldRefreshLibrary = + processedDelta >= PROGRESS_REFRESH_DELTA || + elapsedSinceRefresh >= PROGRESS_REFRESH_INTERVAL_MS; + + if (!shouldRefreshLibrary || refreshInFlightRef.current) { return; } lastProcessedRef.current = totalProcessed; lastLibraryRefreshRef.current = now; + refreshInFlightRef.current = true; const mediaStore = useMediaLibraryStore.getState(); const activeIds = mediaStore.activeLibraryIds || []; - void mediaStore.fetchItems( - activeIds.length > 0 ? activeIds : undefined - ); + + void mediaStore + .fetchItems(activeIds.length > 0 ? activeIds : undefined) + .finally(() => { + refreshInFlightRef.current = false; + }); }, [opened, hasRunningScan, hasQueuedScan, totalProcessed]); useEffect(() => {