From 12cbe842cee04311d21883d5c525393a5cffd7a8 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Thu, 19 Aug 2021 16:01:42 +0900 Subject: [PATCH] improve large playlist performance --- app/state/musicmap.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/state/musicmap.ts b/app/state/musicmap.ts index dbe0c13..75ce9f9 100644 --- a/app/state/musicmap.ts +++ b/app/state/musicmap.ts @@ -20,8 +20,8 @@ import { GetState, SetState } from 'zustand' import { Store } from './store' export type MusicMapSlice = { - mapChildToSong: (child: ChildElement) => Promise - mapChildrenToSongs: (children: ChildElement[]) => Promise + mapChildToSong: (child: ChildElement, coverArt?: string) => Promise + mapChildrenToSongs: (children: ChildElement[], coverArt?: string) => Promise mapArtistID3toArtist: (artist: ArtistID3Element) => Artist mapArtistInfo: ( artistResponse: GetArtistResponse, @@ -36,7 +36,7 @@ export type MusicMapSlice = { } export const createMusicMapSlice = (set: SetState, get: GetState): MusicMapSlice => ({ - mapChildToSong: async child => { + mapChildToSong: async (child, coverArt) => { return { itemType: 'song', id: child.id, @@ -48,15 +48,15 @@ export const createMusicMapSlice = (set: SetState, get: GetState): track: child.track, duration: child.duration, starred: child.starred, - coverArt: await get().getAlbumCoverArt(child.albumId), + coverArt: coverArt || (await get().getAlbumCoverArt(child.albumId)), streamUri: get().buildStreamUri(child.id), } }, - mapChildrenToSongs: async children => { + mapChildrenToSongs: async (children, coverArt) => { const songMaps: Promise[] = [] for (const child of children) { - songMaps.push(get().mapChildToSong(child)) + songMaps.push(get().mapChildToSong(child, coverArt)) } return await Promise.all(songMaps) }, @@ -125,7 +125,8 @@ export const createMusicMapSlice = (set: SetState, get: GetState): mapPlaylistWithSongs: async playlist => { return { ...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, } },