fix polling for musicbrainz worker
This commit is contained in:
parent
fa808e5bba
commit
2a4cab3f96
2 changed files with 40 additions and 16 deletions
|
|
@ -336,48 +336,48 @@ class MusicBrainzWorker:
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) AS total,
|
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
|
FROM artists
|
||||||
""")
|
""")
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
total, matched = row[0], row[1] or 0
|
total, processed = row[0], row[1] or 0
|
||||||
progress['artists'] = {
|
progress['artists'] = {
|
||||||
'matched': matched,
|
'matched': processed, # Actually "processed" count for UI
|
||||||
'total': total,
|
'total': total,
|
||||||
'percent': int((matched / total * 100) if total > 0 else 0)
|
'percent': int((processed / total * 100) if total > 0 else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Albums progress
|
# Albums progress
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) AS total,
|
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
|
FROM albums
|
||||||
""")
|
""")
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
total, matched = row[0], row[1] or 0
|
total, processed = row[0], row[1] or 0
|
||||||
progress['albums'] = {
|
progress['albums'] = {
|
||||||
'matched': matched,
|
'matched': processed,
|
||||||
'total': total,
|
'total': total,
|
||||||
'percent': int((matched / total * 100) if total > 0 else 0)
|
'percent': int((processed / total * 100) if total > 0 else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Tracks progress
|
# Tracks progress
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) AS total,
|
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
|
FROM tracks
|
||||||
""")
|
""")
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if row:
|
if row:
|
||||||
total, matched = row[0], row[1] or 0
|
total, processed = row[0], row[1] or 0
|
||||||
progress['tracks'] = {
|
progress['tracks'] = {
|
||||||
'matched': matched,
|
'matched': processed,
|
||||||
'total': total,
|
'total': total,
|
||||||
'percent': int((matched / total * 100) if total > 0 else 0)
|
'percent': int((processed / total * 100) if total > 0 else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return progress
|
return progress
|
||||||
|
|
|
||||||
|
|
@ -34221,10 +34221,34 @@ async function updateMusicBrainzStatus() {
|
||||||
|
|
||||||
if (tooltipProgress && data.progress) {
|
if (tooltipProgress && data.progress) {
|
||||||
const artists = data.progress.artists || {};
|
const artists = data.progress.artists || {};
|
||||||
const matched = artists.matched || 0;
|
const albums = data.progress.albums || {};
|
||||||
const total = artists.total || 0;
|
const tracks = data.progress.tracks || {};
|
||||||
const percent = total > 0 ? Math.round((matched / total) * 100) : 0;
|
|
||||||
tooltipProgress.textContent = `Progress: ${matched} / ${total} artists (${percent}%)`;
|
// 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) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue