From f9102444efb79aab4160fb431b50f41c357317f4 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Tue, 7 Oct 2025 21:34:39 +0200 Subject: [PATCH] feat: enhance cache clearing process with revalidation of important paths and improve logging in BaseApiService --- src/app/api/komga/cache/clear/route.ts | 10 +++++++++- src/lib/services/base-api.service.ts | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/app/api/komga/cache/clear/route.ts b/src/app/api/komga/cache/clear/route.ts index 7a17e9e..bf3131f 100644 --- a/src/app/api/komga/cache/clear/route.ts +++ b/src/app/api/komga/cache/clear/route.ts @@ -3,11 +3,19 @@ import type { ServerCacheService } from "@/lib/services/server-cache.service"; import { getServerCacheService } from "@/lib/services/server-cache.service"; import { ERROR_CODES } from "@/constants/errorCodes"; import { getErrorMessage } from "@/utils/errors"; +import { revalidatePath } from "next/cache"; export async function POST() { try { const cacheService: ServerCacheService = await getServerCacheService(); - cacheService.clear(); + await cacheService.clear(); + + // Revalider toutes les pages importantes après le vidage du cache + revalidatePath("/"); + revalidatePath("/libraries"); + revalidatePath("/series"); + revalidatePath("/books"); + return NextResponse.json({ message: "🧹 Cache vidé avec succès" }); } catch (error) { console.error("Erreur lors de la suppression du cache:", error); diff --git a/src/lib/services/base-api.service.ts b/src/lib/services/base-api.service.ts index 85e55af..c6573a0 100644 --- a/src/lib/services/base-api.service.ts +++ b/src/lib/services/base-api.service.ts @@ -5,7 +5,7 @@ import { ERROR_CODES } from "../../constants/errorCodes"; import { AppError } from "../../utils/errors"; import type { KomgaConfig } from "@/types/komga"; import type { ServerCacheService } from "./server-cache.service"; -import { fetchWithCacheDetection } from "../utils/fetch-with-cache-detection"; +import { DebugService } from "./debug.service"; // Types de cache disponibles export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES"; @@ -97,8 +97,19 @@ export abstract class BaseApiService { } } + const startTime = performance.now(); + try { - const response = await fetchWithCacheDetection(url, { headers, ...options }); + const response = await fetch(url, { headers, ...options }); + const endTime = performance.now(); + + // Logger la requête côté serveur + await DebugService.logRequest({ + url: url, + startTime, + endTime, + fromCache: false, // Côté serveur, on ne peut pas détecter le cache navigateur + }); if (!response.ok) { throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, { @@ -109,6 +120,16 @@ export abstract class BaseApiService { return options.isImage ? (response as T) : response.json(); } catch (error) { + const endTime = performance.now(); + + // Logger l'erreur côté serveur + await DebugService.logRequest({ + url: url, + startTime, + endTime, + fromCache: false, + }); + throw error; } }