fix potential null errors in recordData/graphPeakData
This commit is contained in:
parent
f4dadd9805
commit
05df7081e4
@ -77,10 +77,12 @@ class Database {
|
||||
|
||||
// Query recordData
|
||||
// When complete increment completeTasks to know when complete
|
||||
this.getRecord(serverRegistration.data.ip, (playerCount, timestamp) => {
|
||||
serverRegistration.recordData = {
|
||||
playerCount,
|
||||
timestamp: TimeTracker.toSeconds(timestamp)
|
||||
this.getRecord(serverRegistration.data.ip, (hasRecord, playerCount, timestamp) => {
|
||||
if (hasRecord) {
|
||||
serverRegistration.recordData = {
|
||||
playerCount,
|
||||
timestamp: TimeTracker.toSeconds(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if completedTasks hit the finish value
|
||||
@ -102,7 +104,21 @@ class Database {
|
||||
getRecord (ip, callback) {
|
||||
this._sql.all('SELECT MAX(playerCount), timestamp FROM pings WHERE ip = ?', [
|
||||
ip
|
||||
], (_, data) => callback(data[0]['MAX(playerCount)'], data[0].timestamp))
|
||||
], (_, data) => {
|
||||
// For empty results, data will be length 1 with [null, null]
|
||||
const playerCount = data[0]['MAX(playerCount)']
|
||||
const timestamp = data[0].timestamp
|
||||
|
||||
// Allow null timestamps, the frontend will safely handle them
|
||||
// This allows insertion of free standing records without a known timestamp
|
||||
if (playerCount !== null) {
|
||||
// eslint-disable-next-line standard/no-callback-literal
|
||||
callback(true, playerCount, timestamp)
|
||||
} else {
|
||||
// eslint-disable-next-line standard/no-callback-literal
|
||||
callback(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
insertPing (ip, timestamp, unsafePlayerCount) {
|
||||
|
@ -132,7 +132,7 @@ class ServerRegistration {
|
||||
let index = -1
|
||||
for (let i = 0; i < this.graphData.length; i++) {
|
||||
const point = this.graphData[i]
|
||||
if (index === -1 || point > this.graphData[index]) {
|
||||
if (point !== null && (index === -1 || point > this.graphData[index])) {
|
||||
index = i
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user