mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
optimize ND/JF list fetch
- no longer requires 2 separate fetches for count and data - the list count includes the first page so we set the query data directly
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { queryOptions } from '@tanstack/react-query';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { controller } from '/@/renderer/api/controller';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { getOptimizedListCount } from '/@/renderer/api/utils-list-count';
|
||||
import { QueryHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { AlbumDetailQuery, AlbumListQuery, ListCountQuery } from '/@/shared/types/domain-types';
|
||||
|
||||
@@ -36,8 +38,25 @@ export const albumQueries = {
|
||||
},
|
||||
listCount: (args: QueryHookArgs<ListCountQuery<AlbumListQuery>>) => {
|
||||
return queryOptions({
|
||||
gcTime: 1000 * 60 * 60 * 12,
|
||||
queryFn: ({ signal }) => {
|
||||
gcTime: 1000 * 60 * 60,
|
||||
queryFn: async ({ client, signal }) => {
|
||||
const optimizedCount = await getOptimizedListCount<
|
||||
ListCountQuery<AlbumListQuery>,
|
||||
AlbumListQuery,
|
||||
{ totalRecordCount: null | number }
|
||||
>({
|
||||
client,
|
||||
listQueryFn: controller.getAlbumList,
|
||||
listQueryKeyFn: (serverId, query) => queryKeys.albums.list(serverId, query),
|
||||
query: args.query,
|
||||
serverId: args.serverId,
|
||||
signal,
|
||||
});
|
||||
|
||||
if (optimizedCount !== null) {
|
||||
return optimizedCount;
|
||||
}
|
||||
|
||||
return api.controller.getAlbumListCount({
|
||||
apiClientProps: { serverId: args.serverId, signal },
|
||||
query: args.query,
|
||||
@@ -48,7 +67,7 @@ export const albumQueries = {
|
||||
args.query,
|
||||
args.query?.artistIds?.length === 1 ? args.query?.artistIds[0] : undefined,
|
||||
),
|
||||
staleTime: 1000 * 60 * 60 * 12,
|
||||
staleTime: 1000 * 60 * 60,
|
||||
...args.options,
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user