mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-29 09:29:29 +01:00
improve large playlist performance
This commit is contained in:
parent
9b50107b35
commit
12cbe842ce
@ -20,8 +20,8 @@ import { GetState, SetState } from 'zustand'
|
|||||||
import { Store } from './store'
|
import { Store } from './store'
|
||||||
|
|
||||||
export type MusicMapSlice = {
|
export type MusicMapSlice = {
|
||||||
mapChildToSong: (child: ChildElement) => Promise<Song>
|
mapChildToSong: (child: ChildElement, coverArt?: string) => Promise<Song>
|
||||||
mapChildrenToSongs: (children: ChildElement[]) => Promise<Song[]>
|
mapChildrenToSongs: (children: ChildElement[], coverArt?: string) => Promise<Song[]>
|
||||||
mapArtistID3toArtist: (artist: ArtistID3Element) => Artist
|
mapArtistID3toArtist: (artist: ArtistID3Element) => Artist
|
||||||
mapArtistInfo: (
|
mapArtistInfo: (
|
||||||
artistResponse: GetArtistResponse,
|
artistResponse: GetArtistResponse,
|
||||||
@ -36,7 +36,7 @@ export type MusicMapSlice = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>): MusicMapSlice => ({
|
export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>): MusicMapSlice => ({
|
||||||
mapChildToSong: async child => {
|
mapChildToSong: async (child, coverArt) => {
|
||||||
return {
|
return {
|
||||||
itemType: 'song',
|
itemType: 'song',
|
||||||
id: child.id,
|
id: child.id,
|
||||||
@ -48,15 +48,15 @@ export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>):
|
|||||||
track: child.track,
|
track: child.track,
|
||||||
duration: child.duration,
|
duration: child.duration,
|
||||||
starred: child.starred,
|
starred: child.starred,
|
||||||
coverArt: await get().getAlbumCoverArt(child.albumId),
|
coverArt: coverArt || (await get().getAlbumCoverArt(child.albumId)),
|
||||||
streamUri: get().buildStreamUri(child.id),
|
streamUri: get().buildStreamUri(child.id),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mapChildrenToSongs: async children => {
|
mapChildrenToSongs: async (children, coverArt) => {
|
||||||
const songMaps: Promise<Song>[] = []
|
const songMaps: Promise<Song>[] = []
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
songMaps.push(get().mapChildToSong(child))
|
songMaps.push(get().mapChildToSong(child, coverArt))
|
||||||
}
|
}
|
||||||
return await Promise.all(songMaps)
|
return await Promise.all(songMaps)
|
||||||
},
|
},
|
||||||
@ -125,7 +125,8 @@ export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>):
|
|||||||
mapPlaylistWithSongs: async playlist => {
|
mapPlaylistWithSongs: async playlist => {
|
||||||
return {
|
return {
|
||||||
...get().mapPlaylistListItem(playlist),
|
...get().mapPlaylistListItem(playlist),
|
||||||
songs: await get().mapChildrenToSongs(playlist.songs),
|
// passing cover art here is a temp fix to improve large playlist performance
|
||||||
|
songs: await get().mapChildrenToSongs(playlist.songs, playlist.coverArt),
|
||||||
coverArt: playlist.coverArt,
|
coverArt: playlist.coverArt,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user