From 6a722102c5f2b0e948162710652d00945ee4c475 Mon Sep 17 00:00:00 2001 From: mikiher Date: Fri, 17 Nov 2023 08:49:40 +0200 Subject: [PATCH] Use ApiCacheManager & timing middleware --- server/Server.js | 5 +++++ server/routers/ApiRouter.js | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/Server.js b/server/Server.js index ba63b2bd..f90e9754 100644 --- a/server/Server.js +++ b/server/Server.js @@ -31,7 +31,9 @@ const PodcastManager = require('./managers/PodcastManager') const AudioMetadataMangaer = require('./managers/AudioMetadataManager') const RssFeedManager = require('./managers/RssFeedManager') const CronManager = require('./managers/CronManager') +const ApiCacheManager = require('./managers/ApiCacheManager') const LibraryScanner = require('./scanner/LibraryScanner') +const { measureMiddleware } = require('./utils/timing') class Server { constructor(SOURCE, PORT, HOST, UID, GID, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH) { @@ -67,6 +69,7 @@ class Server { this.audioMetadataManager = new AudioMetadataMangaer() this.rssFeedManager = new RssFeedManager() this.cronManager = new CronManager(this.podcastManager) + this.apiCacheManager = new ApiCacheManager() // Routers this.apiRouter = new ApiRouter(this) @@ -110,6 +113,7 @@ class Server { const libraries = await Database.libraryModel.getAllOldLibraries() await this.cronManager.init(libraries) + this.apiCacheManager.init() if (Database.serverSettings.scannerDisableWatcher) { Logger.info(`[Server] Watcher is disabled`) @@ -130,6 +134,7 @@ class Server { this.server = http.createServer(app) + router.use(measureMiddleware) router.use(this.auth.cors) router.use(fileUpload({ defCharset: 'utf8', diff --git a/server/routers/ApiRouter.js b/server/routers/ApiRouter.js index bb91e9b5..43c32628 100644 --- a/server/routers/ApiRouter.js +++ b/server/routers/ApiRouter.js @@ -32,6 +32,7 @@ const MiscController = require('../controllers/MiscController') const Author = require('../objects/entities/Author') const Series = require('../objects/entities/Series') +const { measureMiddleware } = require('../utils/timing') class ApiRouter { constructor(Server) { @@ -47,6 +48,7 @@ class ApiRouter { this.cronManager = Server.cronManager this.notificationManager = Server.notificationManager this.emailManager = Server.emailManager + this.apiCacheManager = Server.apiCacheManager this.router = express() this.router.disable('x-powered-by') @@ -54,16 +56,17 @@ class ApiRouter { } init() { + const cacheMiddleware = this.apiCacheManager.middleware // // Library Routes // this.router.post('/libraries', LibraryController.create.bind(this)) this.router.get('/libraries', LibraryController.findAll.bind(this)) - this.router.get('/libraries/:id', LibraryController.middleware.bind(this), LibraryController.findOne.bind(this)) + this.router.get('/libraries/:id', LibraryController.middleware.bind(this), cacheMiddleware, LibraryController.findOne.bind(this)) this.router.patch('/libraries/:id', LibraryController.middleware.bind(this), LibraryController.update.bind(this)) this.router.delete('/libraries/:id', LibraryController.middleware.bind(this), LibraryController.delete.bind(this)) - this.router.get('/libraries/:id/items', LibraryController.middleware.bind(this), LibraryController.getLibraryItems.bind(this)) + this.router.get('/libraries/:id/items', LibraryController.middleware.bind(this), cacheMiddleware, LibraryController.getLibraryItems.bind(this)) this.router.delete('/libraries/:id/issues', LibraryController.middleware.bind(this), LibraryController.removeLibraryItemsWithIssues.bind(this)) this.router.get('/libraries/:id/episode-downloads', LibraryController.middleware.bind(this), LibraryController.getEpisodeDownloadQueue.bind(this)) this.router.get('/libraries/:id/series', LibraryController.middleware.bind(this), LibraryController.getAllSeriesForLibrary.bind(this))