mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
refactor(player): E.17 — extract stream-cache-to-hot-cache promoter (#580)
`promoteCompletedStreamToHotCache` — wraps the `promote_stream_cache_to_hot_cache` Rust IPC, forwards the resolved path + size into `useHotCacheStore` as a `'stream-promote'` entry — moves into `src/store/promoteStreamCache.ts`. File-private with four call sites; no caller-side changes outside playerStore's own import. 9 focused tests pin the payload shape (incl. the `'mp3'` suffix fallback and the null customDir pass-through), the success path that records the entry, the early-returns for null / empty path, the `size || 0` fallback, and the silent error swallow. playerStore 3207 → 3189 LOC.
This commit is contained in:
committed by
GitHub
parent
3a99be4daa
commit
9029ab8ec5
@@ -104,6 +104,7 @@ import {
|
||||
setBytePreloadingId,
|
||||
setGaplessPreloadingId,
|
||||
} from './gaplessPreloadState';
|
||||
import { promoteCompletedStreamToHotCache } from './promoteStreamCache';
|
||||
|
||||
// Re-export so TauriEventBridge + persistence test keep their existing
|
||||
// `from './playerStore'` imports.
|
||||
@@ -807,25 +808,6 @@ function prefetchLoudnessForEnqueuedTracks(
|
||||
}
|
||||
}
|
||||
|
||||
async function promoteCompletedStreamToHotCache(track: Track, serverId: string, customDir: string | null) {
|
||||
try {
|
||||
const res = await invoke<{ path: string; size: number } | null>(
|
||||
'promote_stream_cache_to_hot_cache',
|
||||
{
|
||||
trackId: track.id,
|
||||
serverId,
|
||||
url: buildStreamUrl(track.id),
|
||||
suffix: track.suffix || 'mp3',
|
||||
customDir,
|
||||
},
|
||||
);
|
||||
if (!res || !res.path) return;
|
||||
useHotCacheStore.getState().setEntry(track.id, serverId, res.path, res.size || 0, 'stream-promote');
|
||||
} catch {
|
||||
// best-effort promotion; normal hot-cache prefetch remains fallback
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Audio event handlers (called from initAudioListeners) ───────────────────
|
||||
|
||||
function handleAudioPlaying(_duration: number) {
|
||||
|
||||
Reference in New Issue
Block a user