feat: add "files in albums" to albums stats

This commit is contained in:
Bobby Wibowo 2021-01-08 11:18:50 +07:00
parent defa3f2a8c
commit 991d743ef0
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 9 additions and 0 deletions

View File

@ -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)) {

View File

@ -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