perf: skip checking zips on disk for album stats

Closes #353.
This commit is contained in:
Bobby Wibowo 2021-01-08 11:03:26 +07:00
parent afa09b0312
commit defa3f2a8c
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -874,7 +874,6 @@ self.stats = async (req, res, next) => {
const albums = await db.table('albums')
stats[data.title].Total = albums.length
const identifiers = []
for (const album of albums) {
if (!album.enabled) {
stats[data.title].Disabled++
@ -882,19 +881,9 @@ self.stats = async (req, res, next) => {
}
if (album.download) stats[data.title].Downloadable++
if (album.public) stats[data.title].Public++
if (album.zipGeneratedAt) identifiers.push(album.identifier)
if (album.zipGeneratedAt) stats[data.title]['ZIP Generated']++
}
await Promise.all(identifiers.map(async identifier => {
try {
await paths.access(path.join(paths.zips, `${identifier}.zip`))
stats[data.title]['ZIP Generated']++
} catch (error) {
// Re-throw error
if (error.code !== 'ENOENT') throw error
}
}))
// Update cache
data.cache = stats[data.title]
data.generating = false