add serverGraphDuration config option
This commit is contained in:
@ -14,27 +14,19 @@ class Database {
|
||||
})
|
||||
}
|
||||
|
||||
loadGraphPoints (graphDuration, callback) {
|
||||
// Query recent pings
|
||||
const endTime = new Date().getTime()
|
||||
const startTime = endTime - graphDuration
|
||||
|
||||
this.getRecentPings(startTime, endTime, pingData => {
|
||||
loadGraphPoints (length, callback) {
|
||||
this.getRecentPings(length, pingData => {
|
||||
const graphPointsByIp = []
|
||||
|
||||
for (const row of pingData) {
|
||||
// Avoid loading outdated records
|
||||
// This shouldn't happen and is mostly a sanity measure
|
||||
if (startTime - row.timestamp <= graphDuration) {
|
||||
// Load into temporary array
|
||||
// This will be culled prior to being pushed to the serverRegistration
|
||||
let graphPoints = graphPointsByIp[row.ip]
|
||||
if (!graphPoints) {
|
||||
graphPoints = graphPointsByIp[row.ip] = []
|
||||
}
|
||||
|
||||
graphPoints.push([row.timestamp, row.playerCount])
|
||||
// Load into temporary array
|
||||
// This will be culled prior to being pushed to the serverRegistration
|
||||
let graphPoints = graphPointsByIp[row.ip]
|
||||
if (!graphPoints) {
|
||||
graphPoints = graphPointsByIp[row.ip] = []
|
||||
}
|
||||
|
||||
graphPoints.push([row.timestamp, row.playerCount])
|
||||
}
|
||||
|
||||
Object.keys(graphPointsByIp).forEach(ip => {
|
||||
@ -80,10 +72,9 @@ class Database {
|
||||
})
|
||||
}
|
||||
|
||||
getRecentPings (startTime, endTime, callback) {
|
||||
this._sql.all('SELECT * FROM pings WHERE timestamp >= ? AND timestamp <= ?', [
|
||||
startTime,
|
||||
endTime
|
||||
getRecentPings (length, callback) {
|
||||
this._sql.all('SELECT * FROM pings WHERE 1 LIMIT ?', [
|
||||
length
|
||||
], (_, data) => callback(data))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user