improve ping db pruning
This commit is contained in:
parent
d38ee58ec4
commit
0936874c78
1 changed files with 8 additions and 4 deletions
|
|
@ -244,16 +244,20 @@ exports.cartridgeCounts = function cartridgeCounts (deviceId) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: since we only prune on insert, we'll always have
|
||||||
|
// last known state.
|
||||||
exports.machineEvent = function machineEvent (rec) {
|
exports.machineEvent = function machineEvent (rec) {
|
||||||
const TTL = 2 * 60 * 60 * 1000
|
|
||||||
const fields = ['id', 'device_id', 'event_type', 'note', 'device_time']
|
const fields = ['id', 'device_id', 'event_type', 'note', 'device_time']
|
||||||
const sql = getInsertQuery('machine_events', fields)
|
const sql = getInsertQuery('machine_events', fields)
|
||||||
const values = [rec.id, rec.deviceId, rec.eventType, rec.note, rec.deviceTime]
|
const values = [rec.id, rec.deviceId, rec.eventType, rec.note, rec.deviceTime]
|
||||||
const deleteSql = 'DELETE FROM machine_events WHERE (EXTRACT(EPOCH FROM (now() - created))) * 1000 > $1'
|
|
||||||
const deleteValues = [TTL]
|
const deleteSql = `delete from machine_events
|
||||||
|
where device_id=$1
|
||||||
|
and event_type=$2
|
||||||
|
and created < now() - interval '2 hours'`
|
||||||
|
|
||||||
return db.none(sql, values)
|
return db.none(sql, values)
|
||||||
.then(() => db.none(deleteSql, deleteValues))
|
.then(() => db.none(deleteSql, [rec.deviceId, rec.eventType]))
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.devices = function devices () {
|
exports.devices = function devices () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue