perf: optimize Komga caching with unstable_cache for POST requests and reduce API calls
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled

- Fix POST requests (series/list, books/list) not being cached by Next.js fetch cache
  by wrapping them with unstable_cache in the private fetch method
- Wrap getHomeData() entirely with unstable_cache so all 5 home requests are cached
  as a single unit, reducing cold-start cost from 5 parallel calls to 0 on cache hit
- Remove N+1 book count enrichment from getLibraries() (8 extra calls per cold start)
  as LibraryDto does not return booksCount and the value was only used in BackgroundSettings
- Simplify getLibraryById() to reuse cached getLibraries() data instead of making
  separate HTTP calls (saves 2 calls per library page load)
- Fix cache debug logs: replace misleading x-nextjs-cache header check (always UNKNOWN
  on external APIs) with pre-request logs showing the configured cache strategy
- Remove book count display from BackgroundSettings as it is no longer fetched

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 23:10:31 +01:00
parent 8d1f91d636
commit 539bb34716
8 changed files with 57 additions and 108 deletions

View File

@@ -134,7 +134,9 @@
},
"error": {
"title": "Error saving configuration",
"message": "An error occurred while saving the configuration"
"message": "An error occurred while saving the configuration",
"connectionTitle": "Connection error",
"connectionMessage": "Unable to connect to the Komga server. Check the URL and credentials."
}
},
"cache": {
@@ -361,7 +363,6 @@
"errors": {
"MONGODB_MISSING_URI": "MongoDB URI missing",
"MONGODB_CONNECTION_FAILED": "MongoDB connection failed",
"AUTH_UNAUTHENTICATED": "Unauthenticated",
"AUTH_INVALID_CREDENTIALS": "Invalid credentials",
"AUTH_PASSWORD_NOT_STRONG": "Password is not strong enough",
@@ -371,7 +372,6 @@
"AUTH_LOGOUT_ERROR": "Error during logout",
"AUTH_LOGIN_ERROR": "Error during login",
"AUTH_REGISTER_ERROR": "Error during registration",
"KOMGA_MISSING_CONFIG": "Komga configuration missing",
"KOMGA_MISSING_CREDENTIALS": "Komga credentials missing",
"KOMGA_CONNECTION_ERROR": "Error connecting to Komga server",
@@ -380,25 +380,20 @@
"STRIPSTREAM_MISSING_CONFIG": "Stripstream Librarian configuration missing",
"STRIPSTREAM_CONNECTION_ERROR": "Error connecting to Stripstream Librarian",
"STRIPSTREAM_HTTP_ERROR": "HTTP error while communicating with Stripstream Librarian",
"CONFIG_SAVE_ERROR": "Error saving configuration",
"CONFIG_FETCH_ERROR": "Error fetching configuration",
"CONFIG_TTL_SAVE_ERROR": "Error saving TTL configuration",
"CONFIG_TTL_FETCH_ERROR": "Error fetching TTL configuration",
"LIBRARY_NOT_FOUND": "Library not found",
"LIBRARY_FETCH_ERROR": "Error fetching library",
"LIBRARY_SCAN_ERROR": "Error scanning library",
"SERIES_FETCH_ERROR": "Error fetching series",
"SERIES_NO_BOOKS_FOUND": "No books found in series",
"BOOK_NOT_FOUND": "Book not found",
"BOOK_PROGRESS_UPDATE_ERROR": "Error updating reading progress",
"BOOK_PROGRESS_DELETE_ERROR": "Error deleting reading progress",
"BOOK_PAGES_FETCH_ERROR": "Error fetching book pages",
"BOOK_DOWNLOAD_CANCELLED": "Book download cancelled",
"FAVORITE_ADD_ERROR": "Error adding to favorites",
"FAVORITE_DELETE_ERROR": "Error removing from favorites",
"FAVORITE_FETCH_ERROR": "Error fetching favorites",
@@ -406,26 +401,19 @@
"FAVORITE_NETWORK_ERROR": "Network error while accessing favorites",
"FAVORITE_SERVER_ERROR": "Server error while accessing favorites",
"FAVORITE_STATUS_CHECK_ERROR": "Error checking favorites status",
"PREFERENCES_FETCH_ERROR": "Error fetching preferences",
"PREFERENCES_UPDATE_ERROR": "Error updating preferences",
"PREFERENCES_CONTEXT_ERROR": "Preferences context error",
"UI_TABS_TRIGGER_ERROR": "Error triggering tabs",
"UI_TABS_CONTENT_ERROR": "Error loading tabs content",
"IMAGE_FETCH_ERROR": "Error fetching image",
"HOME_FETCH_ERROR": "Error fetching home page",
"MIDDLEWARE_UNAUTHORIZED": "Unauthorized",
"MIDDLEWARE_INVALID_TOKEN": "Invalid authentication token",
"MIDDLEWARE_INVALID_SESSION": "Invalid session",
"CLIENT_FETCH_ERROR": "Error fetching data",
"CLIENT_NETWORK_ERROR": "Network error",
"CLIENT_REQUEST_FAILED": "Request failed",
"GENERIC_ERROR": "An error occurred"
},
"reader": {

View File

@@ -134,7 +134,9 @@
},
"error": {
"title": "Erreur lors de la sauvegarde de la configuration",
"message": "Une erreur est survenue lors de la sauvegarde de la configuration"
"message": "Une erreur est survenue lors de la sauvegarde de la configuration",
"connectionTitle": "Erreur de connexion",
"connectionMessage": "Impossible de se connecter au serveur Komga. Vérifiez l'URL et les identifiants."
}
},
"cache": {
@@ -359,7 +361,6 @@
"errors": {
"MONGODB_MISSING_URI": "URI MongoDB manquante",
"MONGODB_CONNECTION_FAILED": "Erreur lors de la connexion à MongoDB",
"AUTH_UNAUTHENTICATED": "Non authentifié",
"AUTH_INVALID_CREDENTIALS": "Identifiants invalides",
"AUTH_PASSWORD_NOT_STRONG": "Le mot de passe n'est pas assez fort",
@@ -369,7 +370,6 @@
"AUTH_LOGOUT_ERROR": "Erreur lors de la déconnexion",
"AUTH_LOGIN_ERROR": "Erreur lors de la connexion",
"AUTH_REGISTER_ERROR": "Erreur lors de l'inscription",
"KOMGA_MISSING_CONFIG": "Configuration Komga manquante",
"KOMGA_MISSING_CREDENTIALS": "Identifiants Komga manquants",
"KOMGA_CONNECTION_ERROR": "Erreur de connexion au serveur Komga",
@@ -378,25 +378,20 @@
"STRIPSTREAM_MISSING_CONFIG": "Configuration Stripstream Librarian manquante",
"STRIPSTREAM_CONNECTION_ERROR": "Erreur de connexion à Stripstream Librarian",
"STRIPSTREAM_HTTP_ERROR": "Erreur HTTP lors de la communication avec Stripstream Librarian",
"CONFIG_SAVE_ERROR": "Erreur lors de la sauvegarde de la configuration",
"CONFIG_FETCH_ERROR": "Erreur lors de la récupération de la configuration",
"CONFIG_TTL_SAVE_ERROR": "Erreur lors de la sauvegarde des TTL",
"CONFIG_TTL_FETCH_ERROR": "Erreur lors de la récupération des TTL",
"LIBRARY_NOT_FOUND": "Bibliothèque introuvable",
"LIBRARY_FETCH_ERROR": "Erreur lors de la récupération de la bibliothèque",
"LIBRARY_SCAN_ERROR": "Erreur lors de l'analyse de la bibliothèque",
"SERIES_FETCH_ERROR": "Erreur lors de la récupération des séries",
"SERIES_NO_BOOKS_FOUND": "Aucun livre trouvé dans la série",
"BOOK_NOT_FOUND": "Livre introuvable",
"BOOK_PROGRESS_UPDATE_ERROR": "Erreur lors de la mise à jour de la progression",
"BOOK_PROGRESS_DELETE_ERROR": "Erreur lors de la suppression de la progression",
"BOOK_PAGES_FETCH_ERROR": "Erreur lors de la récupération des pages du livre",
"BOOK_DOWNLOAD_CANCELLED": "Téléchargement du livre annulé",
"FAVORITE_ADD_ERROR": "Erreur lors de l'ajout aux favoris",
"FAVORITE_DELETE_ERROR": "Erreur lors de la suppression des favoris",
"FAVORITE_FETCH_ERROR": "Erreur lors de la récupération des favoris",
@@ -404,26 +399,19 @@
"FAVORITE_NETWORK_ERROR": "Erreur réseau lors de l'accès aux favoris",
"FAVORITE_SERVER_ERROR": "Erreur serveur lors de l'accès aux favoris",
"FAVORITE_STATUS_CHECK_ERROR": "Erreur lors de la vérification du statut des favoris",
"PREFERENCES_FETCH_ERROR": "Erreur lors de la récupération des préférences",
"PREFERENCES_UPDATE_ERROR": "Erreur lors de la mise à jour des préférences",
"PREFERENCES_CONTEXT_ERROR": "Erreur de contexte des préférences",
"UI_TABS_TRIGGER_ERROR": "Erreur lors du déclenchement des onglets",
"UI_TABS_CONTENT_ERROR": "Erreur lors du chargement du contenu des onglets",
"IMAGE_FETCH_ERROR": "Erreur lors de la récupération de l'image",
"HOME_FETCH_ERROR": "Erreur lors de la récupération de l'accueil",
"MIDDLEWARE_UNAUTHORIZED": "Non autorisé",
"MIDDLEWARE_INVALID_TOKEN": "Jeton d'authentification invalide",
"MIDDLEWARE_INVALID_SESSION": "Session invalide",
"CLIENT_FETCH_ERROR": "Erreur lors de la récupération des données",
"CLIENT_NETWORK_ERROR": "Erreur réseau",
"CLIENT_REQUEST_FAILED": "La requête a échoué",
"GENERIC_ERROR": "Une erreur est survenue"
},
"reader": {