merge updateHistoryGraph behavior into update flag

This commit is contained in:
Nick Krecklow 2020-04-29 04:21:50 -05:00
parent 7d47e9b5f8
commit 7322b8dc82
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
3 changed files with 28 additions and 26 deletions

View File

@ -62,25 +62,6 @@ document.addEventListener('DOMContentLoaded', function () {
app.graphDisplayManager.initEventListeners()
})
socket.on('updateHistoryGraph', function (data) {
// Skip any incoming updates if the graph is disabled
// The backend shouldn't send these anyways
if (!app.graphDisplayManager.isVisible) {
return
}
const serverRegistration = app.serverRegistry.getServerRegistration(data.serverId)
if (serverRegistration) {
app.graphDisplayManager.addGraphPoint(serverRegistration.serverId, data.timestamp, data.playerCount)
// Only redraw the graph if not mutating hidden data
if (serverRegistration.isVisible) {
app.graphDisplayManager.requestRedraw()
}
}
})
socket.on('add', function (data) {
data.forEach(app.addServer)
})
@ -94,6 +75,20 @@ document.addEventListener('DOMContentLoaded', function () {
if (serverRegistration) {
serverRegistration.updateServerStatus(data, false, app.publicConfig.minecraftVersions)
}
// Use update payloads to conditionally append data to graph
// Skip any incoming updates if the graph is disabled
if (data.updateHistoryGraph && app.graphDisplayManager.isVisible) {
// Update may not be successful, safely append 0 points
const playerCount = data.result ? data.result.players.online : 0
app.graphDisplayManager.addGraphPoint(serverRegistration.serverId, data.timestamp, playerCount)
// Only redraw the graph if not mutating hidden data
if (serverRegistration.isVisible) {
app.graphDisplayManager.requestRedraw()
}
}
})
socket.on('updateMojangServices', function (data) {

View File

@ -109,6 +109,8 @@ class PingController {
serverRegistration.addPing(timestamp, resp)
let updateHistoryGraph = false
if (config.logToDatabase) {
const playerCount = resp ? resp.players.online : 0
@ -116,15 +118,14 @@ class PingController {
this._app.database.insertPing(serverRegistration.data.ip, timestamp, playerCount)
if (serverRegistration.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
this._app.server.broadcast('updateHistoryGraph', {
serverId: serverRegistration.serverId,
playerCount: playerCount,
timestamp: timestamp
})
updateHistoryGraph = true
}
}
this._app.server.broadcast('update', serverRegistration.getUpdate(timestamp, resp, err, version))
// Generate a combined update payload
// This includes any modified fields and flags used by the frontend
// This will not be cached and can contain live metadata
this._app.server.broadcast('update', serverRegistration.getUpdate(timestamp, resp, err, version, updateHistoryGraph))
}
}

View File

@ -14,7 +14,7 @@ class ServerRegistration {
this._pingHistory = []
}
getUpdate (timestamp, resp, err, version) {
getUpdate (timestamp, resp, err, version, updateHistoryGraph) {
const update = {
serverId: this.serverId,
timestamp: timestamp
@ -55,6 +55,12 @@ class ServerRegistration {
if (this.findNewGraphPeak()) {
update.graphPeakData = this.getGraphPeak()
}
// Handled inside logToDatabase to validate logic from #getUpdate call
// Only append when true since an undefined value == false
if (updateHistoryGraph) {
update.updateHistoryGraph = true
}
}
} else if (err) {
// Append a filtered copy of err