From 2a4cab3f967bfeee8de34c4e68fdb736815ecae5 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Tue, 3 Feb 2026 19:47:31 -0800 Subject: [PATCH] fix polling for musicbrainz worker --- core/musicbrainz_worker.py | 24 ++++++++++++------------ webui/static/script.js | 32 ++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/core/musicbrainz_worker.py b/core/musicbrainz_worker.py index 7bfc8566..383d3b98 100644 --- a/core/musicbrainz_worker.py +++ b/core/musicbrainz_worker.py @@ -336,48 +336,48 @@ class MusicBrainzWorker: cursor.execute(""" SELECT COUNT(*) AS total, - SUM(CASE WHEN musicbrainz_match_status = 'matched' THEN 1 ELSE 0 END) AS matched + SUM(CASE WHEN musicbrainz_match_status IS NOT NULL THEN 1 ELSE 0 END) AS processed FROM artists """) row = cursor.fetchone() if row: - total, matched = row[0], row[1] or 0 + total, processed = row[0], row[1] or 0 progress['artists'] = { - 'matched': matched, + 'matched': processed, # Actually "processed" count for UI 'total': total, - 'percent': int((matched / total * 100) if total > 0 else 0) + 'percent': int((processed / total * 100) if total > 0 else 0) } # Albums progress cursor.execute(""" SELECT COUNT(*) AS total, - SUM(CASE WHEN musicbrainz_match_status = 'matched' THEN 1 ELSE 0 END) AS matched + SUM(CASE WHEN musicbrainz_match_status IS NOT NULL THEN 1 ELSE 0 END) AS processed FROM albums """) row = cursor.fetchone() if row: - total, matched = row[0], row[1] or 0 + total, processed = row[0], row[1] or 0 progress['albums'] = { - 'matched': matched, + 'matched': processed, 'total': total, - 'percent': int((matched / total * 100) if total > 0 else 0) + 'percent': int((processed / total * 100) if total > 0 else 0) } # Tracks progress cursor.execute(""" SELECT COUNT(*) AS total, - SUM(CASE WHEN musicbrainz_match_status = 'matched' THEN 1 ELSE 0 END) AS matched + SUM(CASE WHEN musicbrainz_match_status IS NOT NULL THEN 1 ELSE 0 END) AS processed FROM tracks """) row = cursor.fetchone() if row: - total, matched = row[0], row[1] or 0 + total, processed = row[0], row[1] or 0 progress['tracks'] = { - 'matched': matched, + 'matched': processed, 'total': total, - 'percent': int((matched / total * 100) if total > 0 else 0) + 'percent': int((processed / total * 100) if total > 0 else 0) } return progress diff --git a/webui/static/script.js b/webui/static/script.js index 674ea032..ec8ec9b0 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -34221,10 +34221,34 @@ async function updateMusicBrainzStatus() { if (tooltipProgress && data.progress) { const artists = data.progress.artists || {}; - const matched = artists.matched || 0; - const total = artists.total || 0; - const percent = total > 0 ? Math.round((matched / total) * 100) : 0; - tooltipProgress.textContent = `Progress: ${matched} / ${total} artists (${percent}%)`; + const albums = data.progress.albums || {}; + const tracks = data.progress.tracks || {}; + + // Determine which phase we're in by checking: + // 1. Current item type (if available) + // 2. Which entity type still has pending work + const currentType = data.current_item?.type; + let progressText = ''; + + // Check if each phase is complete (all items have been attempted) + const artistsComplete = artists.matched >= artists.total; + const albumsComplete = albums.matched >= albums.total; + + if (currentType === 'artist' || (!artistsComplete && !currentType)) { + // Show artists if not complete OR if explicitly processing an artist + progressText = `Artists: ${artists.matched || 0} / ${artists.total} (${artists.percent || 0}%)`; + } else if (currentType === 'album' || (artistsComplete && !albumsComplete)) { + // Show albums if artists done and albums not done + progressText = `Albums: ${albums.matched || 0} / ${albums.total} (${albums.percent || 0}%)`; + } else if (currentType === 'track' || (artistsComplete && albumsComplete)) { + // Show tracks if both artists and albums done + progressText = `Tracks: ${tracks.matched || 0} / ${tracks.total} (${tracks.percent || 0}%)`; + } else { + // Fallback to artists + progressText = `Artists: ${artists.matched || 0} / ${artists.total} (${artists.percent || 0}%)`; + } + + tooltipProgress.textContent = progressText; } } catch (error) {