fix potential null errors in recordData/graphPeakData
This commit is contained in:
parent
f4dadd9805
commit
05df7081e4
@ -77,10 +77,12 @@ class Database {
|
|||||||
|
|
||||||
// Query recordData
|
// Query recordData
|
||||||
// When complete increment completeTasks to know when complete
|
// When complete increment completeTasks to know when complete
|
||||||
this.getRecord(serverRegistration.data.ip, (playerCount, timestamp) => {
|
this.getRecord(serverRegistration.data.ip, (hasRecord, playerCount, timestamp) => {
|
||||||
serverRegistration.recordData = {
|
if (hasRecord) {
|
||||||
playerCount,
|
serverRegistration.recordData = {
|
||||||
timestamp: TimeTracker.toSeconds(timestamp)
|
playerCount,
|
||||||
|
timestamp: TimeTracker.toSeconds(timestamp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if completedTasks hit the finish value
|
// Check if completedTasks hit the finish value
|
||||||
@ -102,7 +104,21 @@ class Database {
|
|||||||
getRecord (ip, callback) {
|
getRecord (ip, callback) {
|
||||||
this._sql.all('SELECT MAX(playerCount), timestamp FROM pings WHERE ip = ?', [
|
this._sql.all('SELECT MAX(playerCount), timestamp FROM pings WHERE ip = ?', [
|
||||||
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) {
|
insertPing (ip, timestamp, unsafePlayerCount) {
|
||||||
|
@ -132,7 +132,7 @@ class ServerRegistration {
|
|||||||
let index = -1
|
let index = -1
|
||||||
for (let i = 0; i < this.graphData.length; i++) {
|
for (let i = 0; i < this.graphData.length; i++) {
|
||||||
const point = this.graphData[i]
|
const point = this.graphData[i]
|
||||||
if (index === -1 || point > this.graphData[index]) {
|
if (point !== null && (index === -1 || point > this.graphData[index])) {
|
||||||
index = i
|
index = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user