mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
refactor(device-sync): G.74 — extract helpers + legacy template + fetcher + BrowserRow (cluster) (#641)
Four-cut cluster opening the DeviceSync refactor. 1289 → 1186 LOC (−103). deviceSyncHelpers — uuid, formatBytes, trackToSyncInfo (with the albumArtist-fallback-to-artist logic and the optional playlist context the Rust sync command consumes), plus the SourceTab / SyncStatus / RemovableDrive / SyncTrackMaybePlaylist types. deviceSyncLegacyTemplate — sanitizeComponent (matches Rust's sanitize_path_component) + OldTemplateTrack + applyLegacyTemplate. Lives apart from the general helpers because it's only used by the migration-preview flow and pulls in IS_WINDOWS for path separator. fetchTracksForSource — single async helper that loads the songs for a DeviceSyncSource (playlist / album / artist). Artist sources fan out into parallel getAlbum requests (Navidrome handles them concurrently; the old sequential loop was a ~7 s blocker on 50-album artists). BrowserRow — small button row component used by the source-picker list (playlists / albums / artists tabs). DeviceSync drops the inline definitions plus the direct getAlbum / getPlaylist / getArtist imports that only fetchTracksForSource needed. Pure code move — no behaviour change.
This commit is contained in:
committed by
GitHub
parent
6f8dd73448
commit
31542c9923
@@ -0,0 +1,18 @@
|
||||
import { getArtist } from '../api/subsonicArtists';
|
||||
import { getAlbum } from '../api/subsonicLibrary';
|
||||
import { getPlaylist } from '../api/subsonicPlaylists';
|
||||
import type { SubsonicSong } from '../api/subsonicTypes';
|
||||
import type { DeviceSyncSource } from '../store/deviceSyncStore';
|
||||
|
||||
export async function fetchTracksForSource(source: DeviceSyncSource): Promise<SubsonicSong[]> {
|
||||
if (source.type === 'playlist') { const { songs } = await getPlaylist(source.id); return songs; }
|
||||
if (source.type === 'album') { const { songs } = await getAlbum(source.id); return songs; }
|
||||
const { albums } = await getArtist(source.id);
|
||||
// Parallel album fetches — Navidrome handles getAlbum requests in flight
|
||||
// without serialising. Sequential awaits here multiplied a 50-album artist
|
||||
// sync into 50 round-trips (~7 s blocking) before any device write started.
|
||||
const results = await Promise.all(
|
||||
albums.map(a => getAlbum(a.id).then(r => r.songs).catch(() => [] as SubsonicSong[])),
|
||||
);
|
||||
return results.flat();
|
||||
}
|
||||
Reference in New Issue
Block a user