feat: cache review and home loadings
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ export class ImageService extends BaseApiService {
|
||||
async () => {
|
||||
const response = await fetch(url, { headers });
|
||||
|
||||
// Log du résultat de la requête
|
||||
console.log(`📡 [Komga API] ${response.status} ${response.statusText} - ${url}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
@@ -8,17 +8,18 @@ class ServerCacheService {
|
||||
private static instance: ServerCacheService;
|
||||
private cache: Map<string, { data: unknown; expiry: number }> = new Map();
|
||||
|
||||
private static readonly fiveMinutes = 5 * 60;
|
||||
private static readonly tenMinutes = 10 * 60;
|
||||
private static readonly twentyFourHours = 24 * 60 * 60;
|
||||
private static readonly oneMinute = 1 * 60;
|
||||
private static readonly oneWeek = 7 * 24 * 60 * 60;
|
||||
// Configuration des temps de cache en millisecondes
|
||||
private static readonly fiveMinutes = 5 * 60 * 1000;
|
||||
private static readonly tenMinutes = 10 * 60 * 1000;
|
||||
private static readonly twentyFourHours = 24 * 60 * 60 * 1000;
|
||||
private static readonly oneMinute = 1 * 60 * 1000;
|
||||
private static readonly oneWeek = 7 * 24 * 60 * 60 * 1000;
|
||||
private static readonly noCache = 0;
|
||||
|
||||
// Configuration des temps de cache en secondes
|
||||
// Configuration des temps de cache
|
||||
private static readonly DEFAULT_TTL = {
|
||||
DEFAULT: ServerCacheService.fiveMinutes,
|
||||
HOME: ServerCacheService.fiveMinutes,
|
||||
HOME: ServerCacheService.tenMinutes,
|
||||
LIBRARIES: ServerCacheService.twentyFourHours,
|
||||
SERIES: ServerCacheService.fiveMinutes,
|
||||
BOOKS: ServerCacheService.fiveMinutes,
|
||||
@@ -50,7 +51,7 @@ class ServerCacheService {
|
||||
set(key: string, data: any, type: keyof typeof ServerCacheService.DEFAULT_TTL = "DEFAULT"): void {
|
||||
this.cache.set(key, {
|
||||
data,
|
||||
expiry: Date.now() + this.getTTL(type) * 1000,
|
||||
expiry: Date.now() + this.getTTL(type),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,15 +98,16 @@ class ServerCacheService {
|
||||
const cached = this.cache.get(key);
|
||||
|
||||
if (cached && cached.expiry > now) {
|
||||
console.log("Cache hit for key:", key);
|
||||
console.log("✅ Cache hit for key:", key);
|
||||
return cached.data as T;
|
||||
}
|
||||
console.log("❌ Cache not hit for key:", key);
|
||||
|
||||
try {
|
||||
const data = await fetcher();
|
||||
this.cache.set(key, {
|
||||
data,
|
||||
expiry: now + this.getTTL(type) * 1000,
|
||||
expiry: now + this.getTTL(type),
|
||||
});
|
||||
return data;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user