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

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

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