mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 22:45:41 +00:00
fix(home): Discover Songs covers for local-index tracks (#874)
* fix(home): pre-warm and prefetch Discover Songs row covers The Discover Songs raблин. il came out of the cover pipeline merge with two gaps that left its cards stuck on the placeholder disc icon on cold caches. - `warmHomeMainstageCovers` walked `heroAlbums` / `recent` / `random` through `ensureAlbumCoverMisses` + `predecodeWarmAlbums` but skipped `discoverSongs`, so songs that were peeked but missed on disk had to wait for lazy per-card ensure - `Home.tsx`'s `coverPrefetchRegister` lumped `songRefs` into a `cappedRest` slice already saturated by 48 album refs + 16 artist refs at a 24-entry cap, so the song row's background prefetch was discarded entirely Fix: ensure + decode-warm the Discover Songs cells alongside the album rails, and register the song refs in their own bucket with a sane cap and `middle` priority. Both follow the same shape as the working album rails — no behavior change for surfaces that were already painting. * fix(library): resolve track cover art from albumId for local index songs Discover Songs uses runLocalRandomSongs; trackToSong only mapped coverArtId, so rows with empty cover_art_id but a valid album_id showed the disc placeholder. Mirror Rust COALESCE(cover_art_id, album_id) and Live Search's coverArt ?? albumId in trackToSong, SongCard, and Home prefetch. * docs(release): note Discover Songs cover fix in CHANGELOG and credits (PR #874) * docs(release): credit PR #874 to Psychotoxical and cucadmuh jointly * chore(credits): drop PR #874 from settingsCredits — minor fix --------- Co-authored-by: Psychotoxical <171614930+Psychotoxical@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,12 @@ import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { onInvoke } from '@/test/mocks/tauri';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
import { useLibraryIndexStore } from '@/store/libraryIndexStore';
|
||||
import { runLocalAdvancedSearch, runLocalSongBrowse, trackToSong } from './advancedSearchLocal';
|
||||
import {
|
||||
resolveTrackCoverArtId,
|
||||
runLocalAdvancedSearch,
|
||||
runLocalSongBrowse,
|
||||
trackToSong,
|
||||
} from './advancedSearchLocal';
|
||||
|
||||
const opts = (over: Partial<Parameters<typeof runLocalAdvancedSearch>[1]> = {}) => ({
|
||||
query: '',
|
||||
@@ -100,6 +105,30 @@ describe('runLocalAdvancedSearch', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('resolveTrackCoverArtId falls back to albumId when coverArtId is empty', () => {
|
||||
expect(
|
||||
resolveTrackCoverArtId(
|
||||
{ coverArtId: undefined, albumId: 'al-42' },
|
||||
{ coverArt: '', albumId: 'al-42' },
|
||||
),
|
||||
).toBe('al-42');
|
||||
expect(resolveTrackCoverArtId({ coverArtId: 'cv1', albumId: 'al-42' })).toBe('cv1');
|
||||
});
|
||||
|
||||
it('trackToSong sets coverArt from albumId when the index row has no cover_art_id', () => {
|
||||
const song = trackToSong({
|
||||
serverId: 's1',
|
||||
id: 't1',
|
||||
title: 'T',
|
||||
album: 'Alb',
|
||||
albumId: 'al-42',
|
||||
durationSec: 100,
|
||||
syncedAt: 0,
|
||||
rawJson: { id: 't1', title: 'T', artist: 'A', album: 'Alb', albumId: 'al-42', duration: 100 },
|
||||
});
|
||||
expect(song.coverArt).toBe('al-42');
|
||||
});
|
||||
|
||||
it('trackToSong keeps resolved bpm and source over rawJson tag', () => {
|
||||
const song = trackToSong({
|
||||
serverId: 's1',
|
||||
|
||||
@@ -138,6 +138,21 @@ function buildRequest(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cover art id for a library track — mirrors Rust cover backfill
|
||||
* (`COALESCE(cover_art_id, album_id)`). Many servers only expose album art.
|
||||
*/
|
||||
export function resolveTrackCoverArtId(
|
||||
hot: Pick<LibraryTrackDto, 'coverArtId' | 'albumId'>,
|
||||
song: Partial<SubsonicSong> = {},
|
||||
): string | undefined {
|
||||
for (const c of [hot.coverArtId, song.coverArt, hot.albumId, song.albumId]) {
|
||||
const id = typeof c === 'string' ? c.trim() : '';
|
||||
if (id) return id;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function trackToSong(t: LibraryTrackDto): SubsonicSong {
|
||||
const raw = isObject(t.rawJson) ? t.rawJson : {};
|
||||
const resolvedBpm = t.bpm != null && t.bpm > 0 ? t.bpm : undefined;
|
||||
@@ -151,7 +166,7 @@ export function trackToSong(t: LibraryTrackDto): SubsonicSong {
|
||||
duration: t.durationSec,
|
||||
track: t.trackNumber ?? undefined,
|
||||
discNumber: t.discNumber ?? undefined,
|
||||
coverArt: t.coverArtId ?? undefined,
|
||||
coverArt: resolveTrackCoverArtId(t),
|
||||
year: t.year ?? undefined,
|
||||
genre: t.genre ?? undefined,
|
||||
suffix: t.suffix ?? undefined,
|
||||
@@ -167,6 +182,8 @@ export function trackToSong(t: LibraryTrackDto): SubsonicSong {
|
||||
// `rawJson` is the authoritative original song — let it override the
|
||||
// hot-column fallbacks (it carries OpenSubsonic extras too).
|
||||
const merged: SubsonicSong = { ...base, ...(raw as Partial<SubsonicSong>) };
|
||||
const coverArt = resolveTrackCoverArtId(t, merged);
|
||||
if (coverArt) merged.coverArt = coverArt;
|
||||
if (resolvedBpm != null) merged.bpm = resolvedBpm;
|
||||
if (t.bpmSource === 'analysis' || t.bpmSource === 'tag') {
|
||||
merged.localBpmSource = t.bpmSource;
|
||||
|
||||
Reference in New Issue
Block a user