add serverGraphDuration config option
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
const config = require('../config')
|
||||
const minecraftVersions = require('../minecraft_versions')
|
||||
|
||||
const SERVER_GRAPH_DATA_MAX_LENGTH = 72
|
||||
|
||||
class ServerRegistration {
|
||||
serverId
|
||||
lastFavicon
|
||||
@ -10,7 +8,8 @@ class ServerRegistration {
|
||||
recordData
|
||||
graphData = []
|
||||
|
||||
constructor (serverId, data) {
|
||||
constructor (app, serverId, data) {
|
||||
this._app = app
|
||||
this.serverId = serverId
|
||||
this.data = data
|
||||
this._pingHistory = []
|
||||
@ -107,7 +106,7 @@ class ServerRegistration {
|
||||
this._pingHistory.push(ping)
|
||||
|
||||
// Trim pingHistory to avoid memory leaks
|
||||
if (this._pingHistory.length > SERVER_GRAPH_DATA_MAX_LENGTH) {
|
||||
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||
this._pingHistory.shift()
|
||||
}
|
||||
}
|
||||
@ -203,9 +202,10 @@ class ServerRegistration {
|
||||
this.graphData.push([timestamp, playerCount])
|
||||
this._lastGraphDataPush = timestamp
|
||||
|
||||
// Trim old graphPoints according to graphDuration
|
||||
const filterTimestamp = new Date().getTime() - config.graphDuration
|
||||
this.graphData = this.graphData.filter(point => point[0] >= filterTimestamp)
|
||||
// Trim old graphPoints according to #getMaxGraphDataLength
|
||||
if (this.graphData.length > this._app.pingController.getMaxGraphDataLength()) {
|
||||
this.graphData.shift()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user