mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
Updates
Got rid of caching of statistics. The previous implementation wasn't perfect, and too lazy to improve it.
This commit is contained in:
parent
8c3fb78135
commit
3e336e8c6d
@ -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)
|
||||||
|
@ -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 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user