Got rid of caching of statistics.
The previous implementation wasn't perfect, and too lazy to improve it.
This commit is contained in:
Bobby Wibowo 2019-04-06 00:42:38 +07:00
parent 8c3fb78135
commit 3e336e8c6d
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 1 additions and 14 deletions

View File

@ -564,9 +564,6 @@ uploadsController.formatInfoMap = (req, res, user, infoMap) => {
userid: user !== undefined ? user.id : null, userid: user !== undefined ? user.id : null,
timestamp: Math.floor(Date.now() / 1000) timestamp: Math.floor(Date.now() / 1000)
}) })
// Update last upload timestamp
utils.lastUpload = Date.now()
} else { } else {
utils.deleteFile(info.data.filename, req.app.get('uploads-set')).catch(console.error) utils.deleteFile(info.data.filename, req.app.get('uploads-set')).catch(console.error)
existingFiles.push(dbFile) existingFiles.push(dbFile)

View File

@ -9,11 +9,7 @@ const path = require('path')
const perms = require('./permissionController') const perms = require('./permissionController')
const sharp = require('sharp') const sharp = require('sharp')
const utilsController = { const utilsController = {}
lastUpload: Date.now(),
lastStatsBuilt: 0,
cachedStats: {}
}
const uploadsDir = path.join(__dirname, '..', config.uploads.folder) const uploadsDir = path.join(__dirname, '..', config.uploads.folder)
const thumbsDir = path.join(uploadsDir, 'thumbs') const thumbsDir = path.join(uploadsDir, 'thumbs')
@ -459,10 +455,6 @@ utilsController.stats = async (req, res, next) => {
if (platform !== 'win32') if (platform !== 'win32')
system.loadavg = `${os.loadavg().map(load => load.toFixed(2)).join(', ')}` system.loadavg = `${os.loadavg().map(load => load.toFixed(2)).join(', ')}`
// Return cached stats
if (utilsController.lastStatsBuilt > utilsController.lastUpload)
return res.json({ success: true, system, stats: utilsController.cachedStats })
const stats = { const stats = {
uploads: { uploads: {
count: 0, count: 0,
@ -506,8 +498,6 @@ utilsController.stats = async (req, res, next) => {
if (user.permission === perms.permissions[p]) stats.users.permissions[p]++ if (user.permission === perms.permissions[p]) stats.users.permissions[p]++
} }
utilsController.cachedStats = stats
utilsController.lastStatsBuilt = Date.now()
return res.json({ success: true, system, stats }) return res.json({ success: true, system, stats })
} }