Delete old pings also on startup
This commit is contained in:
parent
23b46a3dd5
commit
37a1579b37
@ -22,11 +22,13 @@ class App {
|
|||||||
// Setup database instance
|
// Setup database instance
|
||||||
this.database.ensureIndexes(() => {
|
this.database.ensureIndexes(() => {
|
||||||
this.database.loadGraphPoints(config.graphDuration, () => {
|
this.database.loadGraphPoints(config.graphDuration, () => {
|
||||||
|
this.database.loadRecords(() => {
|
||||||
if (config.deleteOldPings) {
|
if (config.deleteOldPings) {
|
||||||
this.database.initOldPingsDeleter()
|
this.database.initOldPingsDelete(callback)
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
this.database.loadRecords(callback)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -267,12 +267,18 @@ class Database {
|
|||||||
statement.finalize()
|
statement.finalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
initOldPingsDeleter () {
|
initOldPingsDelete (callback) {
|
||||||
// Delete old records every hour
|
// Delete old ping records on startup
|
||||||
|
logger.info('Deleting old ping records..')
|
||||||
|
this.deleteOldPingRecords(() => {
|
||||||
|
// Delete old ping records every hour
|
||||||
setInterval(() => this.deleteOldPingRecords(), 3600000)
|
setInterval(() => this.deleteOldPingRecords(), 3600000)
|
||||||
|
|
||||||
|
callback()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOldPingRecords () {
|
deleteOldPingRecords (callback) {
|
||||||
// The oldest timestamp that will be kept
|
// The oldest timestamp that will be kept
|
||||||
const oldestTimestamp = TimeTracker.getEpochMillis() - config.graphDuration
|
const oldestTimestamp = TimeTracker.getEpochMillis() - config.graphDuration
|
||||||
|
|
||||||
@ -285,6 +291,10 @@ class Database {
|
|||||||
} else {
|
} else {
|
||||||
const deleteTook = TimeTracker.getEpochMillis() - deleteStart
|
const deleteTook = TimeTracker.getEpochMillis() - deleteStart
|
||||||
logger.info(`Old ping records deleted in ${deleteTook}ms`)
|
logger.info(`Old ping records deleted in ${deleteTook}ms`)
|
||||||
|
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
statement.finalize()
|
statement.finalize()
|
||||||
|
Loading…
Reference in New Issue
Block a user