feat: purge history utility
This commit is contained in:
@@ -562,11 +562,24 @@ module.exports = {
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Purge history
|
||||
*/
|
||||
async purgeHistory (obj, args, context) {
|
||||
try {
|
||||
await WIKI.models.pageHistory.purge(args.olderThan)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Page history purged successfully.')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
Page: {
|
||||
async tags (obj) {
|
||||
return await WIKI.models.pages.relatedQuery('tags').for(obj.id)
|
||||
return WIKI.models.pages.relatedQuery('tags').for(obj.id)
|
||||
}
|
||||
// comments(pg) {
|
||||
// return pg.$relatedQuery('comments')
|
||||
|
@@ -149,6 +149,10 @@ type PageMutation {
|
||||
pageId: Int!
|
||||
versionId: Int!
|
||||
): DefaultResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"])
|
||||
|
||||
purgeHistory (
|
||||
olderThan: String!
|
||||
): DefaultResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
|
@@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user