feat: cache review and home loadings

This commit is contained in:
Julien Froidefond
2025-02-16 22:06:15 +01:00
parent 068c623e37
commit c92156ad12
3 changed files with 56 additions and 43 deletions

View File

@@ -14,43 +14,51 @@ export class HomeService extends BaseApiService {
const config = await this.getKomgaConfig();
const headers = this.getAuthHeaders(config);
return this.fetchWithCache<HomeData>(
"home",
async () => {
// Construction des URLs
const ongoingUrl = this.buildUrl(config, "series", {
read_status: "IN_PROGRESS",
sort: "readDate,desc",
page: "0",
size: "20",
media_status: "READY",
});
// Construction des URLs avec des paramètres optimisés
const ongoingUrl = this.buildUrl(config, "series", {
read_status: "IN_PROGRESS",
sort: "readDate,desc",
page: "0",
size: "10",
media_status: "READY",
});
const recentlyReadUrl = this.buildUrl(config, "books/latest", {
page: "0",
size: "20",
});
const recentlyReadUrl = this.buildUrl(config, "books/latest", {
page: "0",
size: "10",
media_status: "READY",
});
const onDeckUrl = this.buildUrl(config, "books/ondeck", {
page: "0",
size: "20",
});
const onDeckUrl = this.buildUrl(config, "books/ondeck", {
page: "0",
size: "10",
media_status: "READY",
});
// Appels API parallèles avec fetchFromApi
const [ongoing, recentlyRead, onDeck] = await Promise.all([
this.fetchFromApi<LibraryResponse<KomgaSeries>>(ongoingUrl, headers),
this.fetchFromApi<LibraryResponse<KomgaBook>>(recentlyReadUrl, headers),
this.fetchFromApi<LibraryResponse<KomgaBook>>(onDeckUrl, headers),
]);
// Appels API parallèles avec cache individuel
const [ongoing, recentlyRead, onDeck] = await Promise.all([
this.fetchWithCache<LibraryResponse<KomgaSeries>>(
"home-ongoing",
async () => this.fetchFromApi<LibraryResponse<KomgaSeries>>(ongoingUrl, headers),
"HOME"
),
this.fetchWithCache<LibraryResponse<KomgaBook>>(
"home-recently-read",
async () => this.fetchFromApi<LibraryResponse<KomgaBook>>(recentlyReadUrl, headers),
"HOME"
),
this.fetchWithCache<LibraryResponse<KomgaBook>>(
"home-on-deck",
async () => this.fetchFromApi<LibraryResponse<KomgaBook>>(onDeckUrl, headers),
"HOME"
),
]);
return {
ongoing: ongoing.content || [],
recentlyRead: recentlyRead.content || [],
onDeck: onDeck.content || [],
};
},
"HOME"
);
return {
ongoing: ongoing.content || [],
recentlyRead: recentlyRead.content || [],
onDeck: onDeck.content || [],
};
} catch (error) {
return this.handleError(error, "Impossible de récupérer les données de la page d'accueil");
}