use config.graphDuration when querying database, not LIMIT

This commit is contained in:
Nick Krecklow 2020-05-08 02:06:39 -05:00
parent 5f2c62c23a
commit 2f1c9c1dce
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
2 changed files with 11 additions and 6 deletions

View File

@ -24,7 +24,7 @@ class App {
// Setup database instance
this.database.ensureIndexes()
this.database.loadGraphPoints(this.pingController.getMaxGraphDataLength(), () => {
this.database.loadGraphPoints(config.graphDuration, () => {
this.database.loadRecords(callback)
})
}

View File

@ -14,8 +14,12 @@ class Database {
})
}
loadGraphPoints (length, callback) {
this.getRecentPings(length, pingData => {
loadGraphPoints (graphDuration, callback) {
// Query recent pings
const endTime = new Date().getTime()
const startTime = endTime - graphDuration
this.getRecentPings(startTime, endTime, length, pingData => {
const graphPointsByIp = []
for (const row of pingData) {
@ -72,9 +76,10 @@ class Database {
})
}
getRecentPings (length, callback) {
this._sql.all('SELECT * FROM pings WHERE 1 LIMIT ?', [
length
getRecentPings (startTime, endTime, callback) {
this._sql.all('SELECT * FROM pings WHERE timestamp >= ? AND timestamp <= ?', [
startTime,
endTime
], (_, data) => callback(data))
}