mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 00:16:21 +00:00
Cache system & disk stats longer
System stats will be cached for only 1000 ms (1 s) Disk stats will be cached for 60000 ms (60 s)
This commit is contained in:
parent
2a81e899b4
commit
ee920f942f
@ -34,11 +34,13 @@ const self = {
|
||||
const statsCache = {
|
||||
system: {
|
||||
cache: null,
|
||||
generating: false
|
||||
generating: false,
|
||||
generatedAt: 0
|
||||
},
|
||||
disk: {
|
||||
cache: null,
|
||||
generating: false
|
||||
generating: false,
|
||||
generatedAt: 0
|
||||
},
|
||||
albums: {
|
||||
cache: null,
|
||||
@ -539,10 +541,12 @@ self.stats = async (req, res, next) => {
|
||||
// System info
|
||||
if (!statsCache.system.cache && statsCache.system.generating) {
|
||||
stats.system = false
|
||||
} else if (statsCache.system.generating) {
|
||||
} else if (((Date.now() - statsCache.system.generatedAt) <= 1000) || statsCache.system.generating) {
|
||||
// Use cache for 1000 ms (1 second)
|
||||
stats.system = statsCache.system.cache
|
||||
} else {
|
||||
statsCache.system.generating = true
|
||||
statsCache.system.generatedAt = Date.now()
|
||||
|
||||
const currentLoad = await si.currentLoad()
|
||||
const mem = await si.mem()
|
||||
@ -574,10 +578,12 @@ self.stats = async (req, res, next) => {
|
||||
if (os.platform === 'linux')
|
||||
if (!statsCache.disk.cache && statsCache.disk.generating) {
|
||||
stats.disk = false
|
||||
} else if (statsCache.disk.generating) {
|
||||
} else if (((Date.now() - statsCache.disk.generatedAt) <= 60000) || statsCache.disk.generating) {
|
||||
// Use cache for 60000 ms (60 seconds)
|
||||
stats.disk = statsCache.disk.cache
|
||||
} else {
|
||||
statsCache.disk.generating = true
|
||||
statsCache.disk.generatedAt = Date.now()
|
||||
|
||||
stats.disk = {
|
||||
_types: {
|
||||
|
Loading…
Reference in New Issue
Block a user