mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36: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 = {
|
const statsCache = {
|
||||||
system: {
|
system: {
|
||||||
cache: null,
|
cache: null,
|
||||||
generating: false
|
generating: false,
|
||||||
|
generatedAt: 0
|
||||||
},
|
},
|
||||||
disk: {
|
disk: {
|
||||||
cache: null,
|
cache: null,
|
||||||
generating: false
|
generating: false,
|
||||||
|
generatedAt: 0
|
||||||
},
|
},
|
||||||
albums: {
|
albums: {
|
||||||
cache: null,
|
cache: null,
|
||||||
@ -539,10 +541,12 @@ self.stats = async (req, res, next) => {
|
|||||||
// System info
|
// System info
|
||||||
if (!statsCache.system.cache && statsCache.system.generating) {
|
if (!statsCache.system.cache && statsCache.system.generating) {
|
||||||
stats.system = false
|
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
|
stats.system = statsCache.system.cache
|
||||||
} else {
|
} else {
|
||||||
statsCache.system.generating = true
|
statsCache.system.generating = true
|
||||||
|
statsCache.system.generatedAt = Date.now()
|
||||||
|
|
||||||
const currentLoad = await si.currentLoad()
|
const currentLoad = await si.currentLoad()
|
||||||
const mem = await si.mem()
|
const mem = await si.mem()
|
||||||
@ -574,10 +578,12 @@ self.stats = async (req, res, next) => {
|
|||||||
if (os.platform === 'linux')
|
if (os.platform === 'linux')
|
||||||
if (!statsCache.disk.cache && statsCache.disk.generating) {
|
if (!statsCache.disk.cache && statsCache.disk.generating) {
|
||||||
stats.disk = false
|
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
|
stats.disk = statsCache.disk.cache
|
||||||
} else {
|
} else {
|
||||||
statsCache.disk.generating = true
|
statsCache.disk.generating = true
|
||||||
|
statsCache.disk.generatedAt = Date.now()
|
||||||
|
|
||||||
stats.disk = {
|
stats.disk = {
|
||||||
_types: {
|
_types: {
|
||||||
|
Loading…
Reference in New Issue
Block a user