Truncate/trim server tables
This commit is contained in:
parent
4640b4a774
commit
67919892e8
5 changed files with 35 additions and 17 deletions
10
lib/logs.js
10
lib/logs.js
|
|
@ -54,6 +54,14 @@ function update (deviceId, logLines) {
|
|||
return _.mapKeys(_.snakeCase, formatted)
|
||||
}, logLines)
|
||||
const sql = pgp.helpers.insert(logs, cs) + 'on conflict do nothing'
|
||||
|
||||
return db.none(sql)
|
||||
}
|
||||
|
||||
function clearOldLogs () {
|
||||
const sql = `delete from logs
|
||||
where timestamp < now() - interval '3 days'`
|
||||
|
||||
return db.none(sql)
|
||||
}
|
||||
|
||||
|
|
@ -87,4 +95,4 @@ function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
|||
}))
|
||||
}
|
||||
|
||||
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen }
|
||||
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen, clearOldLogs }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue