feat: sort genre pills by total play count via backend
Page loads instantly with song-count order, then silently re-sorts once the backend aggregates play counts across all songs. Result cached 20 min server-side to avoid repeated full-library fetches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
790f02e5b4
commit
4f83eebe79
3 files changed
+39
-2
No files matched your search
@@ -182,6 +182,17 @@ async function loadGenreSection() {
|
||||
_renderGenres();
|
||||
if (_allGenres.length > GENRE_LIMIT() && more) more.style.display = '';
|
||||
} catch { el.style.display = 'none'; }
|
||||
// Re-sort by total play count once backend data arrives (non-blocking)
|
||||
if (S.cfg.backendUrl && _allGenres.length) {
|
||||
fetch(`${S.cfg.backendUrl}/api/genre-playcounts?ndUrl=${encodeURIComponent(S.cfg.url)}&user=${encodeURIComponent(S.cfg.user)}&pass=${encodeURIComponent(S.cfg.pass)}`)
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
.then(plays => {
|
||||
if (!plays || !_allGenres.length) return;
|
||||
_allGenres.sort((a, b) => (plays[b.value] || 0) - (plays[a.value] || 0));
|
||||
_renderGenres();
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
function _renderGenres() {
|
||||
|
||||
Reference in new issue
Block a user