merge updateHistoryGraph behavior into update flag
This commit is contained in:
parent
7d47e9b5f8
commit
7322b8dc82
@ -62,25 +62,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
app.graphDisplayManager.initEventListeners()
|
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) {
|
socket.on('add', function (data) {
|
||||||
data.forEach(app.addServer)
|
data.forEach(app.addServer)
|
||||||
})
|
})
|
||||||
@ -94,6 +75,20 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
if (serverRegistration) {
|
if (serverRegistration) {
|
||||||
serverRegistration.updateServerStatus(data, false, app.publicConfig.minecraftVersions)
|
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) {
|
socket.on('updateMojangServices', function (data) {
|
||||||
|
13
lib/ping.js
13
lib/ping.js
@ -109,6 +109,8 @@ class PingController {
|
|||||||
|
|
||||||
serverRegistration.addPing(timestamp, resp)
|
serverRegistration.addPing(timestamp, resp)
|
||||||
|
|
||||||
|
let updateHistoryGraph = false
|
||||||
|
|
||||||
if (config.logToDatabase) {
|
if (config.logToDatabase) {
|
||||||
const playerCount = resp ? resp.players.online : 0
|
const playerCount = resp ? resp.players.online : 0
|
||||||
|
|
||||||
@ -116,15 +118,14 @@ class PingController {
|
|||||||
this._app.database.insertPing(serverRegistration.data.ip, timestamp, playerCount)
|
this._app.database.insertPing(serverRegistration.data.ip, timestamp, playerCount)
|
||||||
|
|
||||||
if (serverRegistration.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
|
if (serverRegistration.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
|
||||||
this._app.server.broadcast('updateHistoryGraph', {
|
updateHistoryGraph = true
|
||||||
serverId: serverRegistration.serverId,
|
|
||||||
playerCount: playerCount,
|
|
||||||
timestamp: timestamp
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class ServerRegistration {
|
|||||||
this._pingHistory = []
|
this._pingHistory = []
|
||||||
}
|
}
|
||||||
|
|
||||||
getUpdate (timestamp, resp, err, version) {
|
getUpdate (timestamp, resp, err, version, updateHistoryGraph) {
|
||||||
const update = {
|
const update = {
|
||||||
serverId: this.serverId,
|
serverId: this.serverId,
|
||||||
timestamp: timestamp
|
timestamp: timestamp
|
||||||
@ -55,6 +55,12 @@ class ServerRegistration {
|
|||||||
if (this.findNewGraphPeak()) {
|
if (this.findNewGraphPeak()) {
|
||||||
update.graphPeakData = this.getGraphPeak()
|
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) {
|
} else if (err) {
|
||||||
// Append a filtered copy of err
|
// Append a filtered copy of err
|
||||||
|
Loading…
Reference in New Issue
Block a user