refactor: optimize book details and pages fetching by using Promise.all for parallel requests
This commit is contained in:
@@ -13,13 +13,11 @@ export class BookService extends BaseApiService {
|
|||||||
return this.fetchWithCache<KomgaBookWithPages>(
|
return this.fetchWithCache<KomgaBookWithPages>(
|
||||||
`book-${bookId}`,
|
`book-${bookId}`,
|
||||||
async () => {
|
async () => {
|
||||||
// Récupération des détails du tome
|
// Récupération parallèle des détails du tome et des pages
|
||||||
const book = await this.fetchFromApi<KomgaBook>({ path: `books/${bookId}` });
|
const [book, pages] = await Promise.all([
|
||||||
|
this.fetchFromApi<KomgaBook>({ path: `books/${bookId}` }),
|
||||||
// Récupération des pages du tome
|
this.fetchFromApi<{ number: number }[]>({ path: `books/${bookId}/pages` })
|
||||||
const pages = await this.fetchFromApi<{ number: number }[]>({
|
]);
|
||||||
path: `books/${bookId}/pages`,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
book,
|
book,
|
||||||
|
|||||||
Reference in New Issue
Block a user