From 991d743ef0e4812bec4d9264f6b88d5d225883ad Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Fri, 8 Jan 2021 11:18:50 +0700 Subject: [PATCH] feat: add "files in albums" to albums stats --- controllers/albumsController.js | 1 + controllers/utilsController.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/controllers/albumsController.js b/controllers/albumsController.js index 011c071..e775409 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -626,6 +626,7 @@ self.addFiles = async (req, res, next) => { await db.table('files') .whereIn('id', files.map(file => file.id)) .update('albumid', albumid) + utils.invalidateStatsCache('albums') files.forEach(file => { if (file.albumid && !albumids.includes(file.albumid)) { diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 8405761..9a2dcfd 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -874,16 +874,24 @@ self.stats = async (req, res, next) => { const albums = await db.table('albums') stats[data.title].Total = albums.length + + const activeAlbums = [] for (const album of albums) { if (!album.enabled) { stats[data.title].Disabled++ continue } + activeAlbums.push(album.id) if (album.download) stats[data.title].Downloadable++ if (album.public) stats[data.title].Public++ if (album.zipGeneratedAt) stats[data.title]['ZIP Generated']++ } + stats[data.title]['Files in albums'] = await db.table('files') + .whereIn('albumid', activeAlbums) + .count('id as count') + .then(rows => rows[0].count) + // Update cache data.cache = stats[data.title] data.generating = false