feat: implement caching strategy for API responses and adjust loading timeout in CoverClient for improved performance

This commit is contained in:
Julien Froidefond
2025-10-17 23:20:42 +02:00
parent a22e77c4eb
commit ae4b766085
8 changed files with 58 additions and 20 deletions

View File

@@ -19,7 +19,9 @@ export function ClientHomePage() {
setError(null);
try {
const response = await fetch("/api/komga/home");
const response = await fetch("/api/komga/home", {
cache: 'default' // Utilise le cache HTTP du navigateur
});
if (!response.ok) {
const errorData = await response.json();
@@ -61,7 +63,9 @@ export function ClientHomePage() {
}
// Récupérer les nouvelles données
const response = await fetch("/api/komga/home");
const response = await fetch("/api/komga/home", {
cache: 'reload' // Force un nouveau fetch après invalidation
});
if (!response.ok) {
throw new Error("Erreur lors du rafraîchissement de la page d'accueil");

View File

@@ -22,14 +22,14 @@ export const CoverClient = ({
const [isLoading, setIsLoading] = useState(true);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
// Timeout de sécurité : si l'image ne se charge pas en 10 secondes, on arrête le loading
// Timeout de sécurité : si l'image ne se charge pas en 30 secondes, on arrête le loading
useEffect(() => {
timeoutRef.current = setTimeout(() => {
if (isLoading) {
console.warn("Image loading timeout for:", imageUrl);
setIsLoading(false);
setImageError(true);
}
}, 10000);
}, 30000);
return () => {
if (timeoutRef.current) {
@@ -49,8 +49,8 @@ export const CoverClient = ({
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
console.error("Image loading error for:", imageUrl);
setImageError(true);
setIsLoading(false);
};
if (imageError) {