work on bulking updateServer payloads and single timestamps

This commit is contained in:
Nick Krecklow
2020-05-08 00:36:15 -05:00
parent a3c88dc0c5
commit 3ddb2c9a08
5 changed files with 90 additions and 53 deletions

View File

@ -14,12 +14,30 @@ class ServerRegistration {
this._pingHistory = []
}
getUpdate (timestamp, resp, err, version, updateHistoryGraph) {
const update = {
serverId: this.serverId,
timestamp: timestamp
handlePing (timestamp, resp, err, version) {
// Store into in-memory ping data
this.addPing(timestamp, resp)
// Only notify the frontend to append to the historical graph
// if both the graphing behavior is enabled and the backend agrees
// that the ping is eligible for addition
let updateHistoryGraph = false
if (config.logToDatabase) {
const playerCount = resp ? resp.players.online : 0
if (this.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
updateHistoryGraph = true
}
}
// Delegate out update payload generation
return this.getUpdate(timestamp, resp, err, version, updateHistoryGraph)
}
getUpdate (timestamp, resp, err, version, updateHistoryGraph) {
const update = {}
if (resp) {
if (resp.version && this.updateProtocolVersionCompat(resp.version, version.protocolId, version.protocolIndex)) {
// Append an updated version listing