feat: purge history utility

This commit is contained in:
NGPixel
2020-09-05 23:32:00 -04:00
parent 8490fc1267
commit ef739de970
4 changed files with 108 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
const Model = require('objection').Model
const _ = require('lodash')
const { DateTime, Duration } = require('luxon')
/* global WIKI */
@@ -228,4 +229,15 @@ module.exports = class PageHistory extends Model {
total: history.total
}
}
/**
* Purge history older than X
*
* @param {String} olderThan ISO 8601 Duration
*/
static async purge (olderThan) {
const dur = Duration.fromISO(olderThan)
const olderThanISO = DateTime.utc().minus(dur)
await WIKI.models.pageHistory.query().where('versionDate', '<', olderThanISO.toISO()).del()
}
}