mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
use batched fetching for nd song list
- albumIds get culled from query parameters after a certain number, resulting in not all items fetched
This commit is contained in:
@@ -744,20 +744,29 @@ export const NavidromeController: InternalControllerEndpoint = {
|
||||
args.context?.pathReplaceWith,
|
||||
);
|
||||
},
|
||||
|
||||
getSongList: async (args) => {
|
||||
const { apiClientProps, query } = args;
|
||||
|
||||
const ALBUM_IDS_BATCH_SIZE = 500;
|
||||
const albumIds = query.albumIds;
|
||||
const shouldBatch = albumIds && albumIds.length > ALBUM_IDS_BATCH_SIZE;
|
||||
|
||||
const fetchAlbums = async (albumIdBatch: string[] | undefined) => {
|
||||
const res = await ndApiClient(apiClientProps).getSongList({
|
||||
query: {
|
||||
_end: query.startIndex + (query.limit || -1),
|
||||
_order: sortOrderMap.navidrome[query.sortOrder],
|
||||
_sort: songListSortMap.navidrome[query.sortBy],
|
||||
_start: query.startIndex,
|
||||
album_id: query.albumIds,
|
||||
album_id: albumIdBatch ?? query.albumIds,
|
||||
genre_id: query.genreIds,
|
||||
[getArtistSongKey(apiClientProps.server)]: query.artistIds ?? query.albumArtistIds,
|
||||
...(hasFeature(apiClientProps.server, ServerFeature.TRACK_YES_NO_RATING_FILTER) &&
|
||||
query.hasRating !== undefined
|
||||
[getArtistSongKey(apiClientProps.server)]:
|
||||
query.artistIds ?? query.albumArtistIds,
|
||||
...(hasFeature(
|
||||
apiClientProps.server,
|
||||
ServerFeature.TRACK_YES_NO_RATING_FILTER,
|
||||
) && query.hasRating !== undefined
|
||||
? { has_rating: query.hasRating }
|
||||
: {}),
|
||||
library_id: getLibraryId(query.musicFolderId),
|
||||
@@ -782,9 +791,32 @@ export const NavidromeController: InternalControllerEndpoint = {
|
||||
args.context?.pathReplaceWith,
|
||||
),
|
||||
),
|
||||
startIndex: query?.startIndex || 0,
|
||||
totalRecordCount: Number(res.body.headers.get('x-total-count') || 0),
|
||||
};
|
||||
};
|
||||
|
||||
if (shouldBatch && albumIds) {
|
||||
const batches: string[][] = [];
|
||||
for (let i = 0; i < albumIds.length; i += ALBUM_IDS_BATCH_SIZE) {
|
||||
batches.push(albumIds.slice(i, i + ALBUM_IDS_BATCH_SIZE));
|
||||
}
|
||||
|
||||
const results = await Promise.all(batches.map((batch) => fetchAlbums(batch)));
|
||||
|
||||
return {
|
||||
items: results.flatMap((r) => r.items),
|
||||
startIndex: query?.startIndex ?? 0,
|
||||
totalRecordCount: results.reduce((sum, r) => sum + r.totalRecordCount, 0),
|
||||
};
|
||||
}
|
||||
|
||||
const albums = await fetchAlbums(undefined);
|
||||
|
||||
return {
|
||||
items: albums.items,
|
||||
startIndex: query?.startIndex ?? 0,
|
||||
totalRecordCount: albums.totalRecordCount,
|
||||
};
|
||||
},
|
||||
getSongListCount: async ({ apiClientProps, query }) =>
|
||||
NavidromeController.getSongList({
|
||||
|
||||
Reference in New Issue
Block a user