mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +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
@@ -0,0 +1,39 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { buildStreamUrl } from '../api/subsonic';
|
||||
import { useHotCacheStore } from './hotCacheStore';
|
||||
import type { Track } from './playerStore';
|
||||
|
||||
/**
|
||||
* Promote a track whose stream cache is full to the on-disk hot cache.
|
||||
* Rust copies the cached bytes into the hot-cache directory and returns
|
||||
* the resolved path + size; the JS-side `useHotCacheStore` index gets the
|
||||
* entry tagged `'stream-promote'` so the LRU treats it the same as a
|
||||
* prefetch hit.
|
||||
*
|
||||
* Best-effort: any failure is swallowed because the regular hot-cache
|
||||
* prefetch path remains a fallback. `customDir` may be null when the user
|
||||
* hasn't picked a hot-cache directory yet — Rust then writes to the
|
||||
* default location.
|
||||
*/
|
||||
export async function promoteCompletedStreamToHotCache(
|
||||
track: Track,
|
||||
serverId: string,
|
||||
customDir: string | null,
|
||||
): Promise<void> {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user