From 3e336e8c6d9a6f41831fc3b26b26bc17f48a67ad Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Sat, 6 Apr 2019 00:42:38 +0700 Subject: [PATCH] Updates Got rid of caching of statistics. The previous implementation wasn't perfect, and too lazy to improve it. --- controllers/uploadController.js | 3 --- controllers/utilsController.js | 12 +----------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 3246437..061d0ab 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -564,9 +564,6 @@ uploadsController.formatInfoMap = (req, res, user, infoMap) => { userid: user !== undefined ? user.id : null, timestamp: Math.floor(Date.now() / 1000) }) - - // Update last upload timestamp - utils.lastUpload = Date.now() } else { utils.deleteFile(info.data.filename, req.app.get('uploads-set')).catch(console.error) existingFiles.push(dbFile) diff --git a/controllers/utilsController.js b/controllers/utilsController.js index ba15040..8d0d3a3 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -9,11 +9,7 @@ const path = require('path') const perms = require('./permissionController') const sharp = require('sharp') -const utilsController = { - lastUpload: Date.now(), - lastStatsBuilt: 0, - cachedStats: {} -} +const utilsController = {} const uploadsDir = path.join(__dirname, '..', config.uploads.folder) const thumbsDir = path.join(uploadsDir, 'thumbs') @@ -459,10 +455,6 @@ utilsController.stats = async (req, res, next) => { if (platform !== 'win32') 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 = { uploads: { count: 0, @@ -506,8 +498,6 @@ utilsController.stats = async (req, res, next) => { if (user.permission === perms.permissions[p]) stats.users.permissions[p]++ } - utilsController.cachedStats = stats - utilsController.lastStatsBuilt = Date.now() return res.json({ success: true, system, stats }) }