mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
fix: add clean unused ap users task
This commit is contained in:
parent
84d2b594a0
commit
ac958b0e4b
2 changed files with 39 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
const { Event, Resource, EventNotification } = require('../api/models/models')
|
||||
const { Event, Resource, EventNotification, APUser } = require('../api/models/models')
|
||||
const { Op } = require('sequelize')
|
||||
const { DateTime } = require('luxon')
|
||||
const log = require('../log')
|
||||
|
@ -15,13 +15,38 @@ module.exports = {
|
|||
|
||||
log.info(`[AP] Remove ${events.length} past federated events and related resources`)
|
||||
const eventsId = events.map(e => e.id)
|
||||
|
||||
// remove related resources..
|
||||
await Resource.destroy({ where: { eventId: eventsId }})
|
||||
|
||||
// ...and notiifcations
|
||||
await EventNotification.destroy({ where: { eventId: eventsId }})
|
||||
|
||||
|
||||
await Event.destroy({ where: { id: eventsId } }).catch(e => {
|
||||
log.debug('[AP] Error while removing past federated events: %s', JSON.stringify(e))
|
||||
})
|
||||
},
|
||||
|
||||
async _cleanUnusedAPUser () {
|
||||
const ap_users = await APUser.findAll({
|
||||
limit: 500,
|
||||
where: {
|
||||
follower: { [Op.not]: true },
|
||||
following: { [Op.not]: true },
|
||||
trusted: { [Op.not]: true },
|
||||
blocked: { [Op.not]: true },
|
||||
},
|
||||
include: [
|
||||
{ model: Event, required: false },
|
||||
{ model: Resource, required: false }
|
||||
],
|
||||
raw: true
|
||||
})
|
||||
|
||||
const ap_ids = ap_users.filter(a => a['events.id'] === null && a['resources.id'] === null).map(a => a.ap_id )
|
||||
if (ap_ids.length) {
|
||||
log.debug('[AP] Remove %d not used federated actors', ap_ids.length)
|
||||
await APUser.destroy({ where: { ap_id: ap_ids } })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ class Task {
|
|||
* - Create recurrent events
|
||||
* - Sync AP federation profiles
|
||||
* - Remove unused tags/places
|
||||
* - Remove past federated events and related resources
|
||||
* - Remove unused ap actors
|
||||
*/
|
||||
|
||||
class TaskManager {
|
||||
|
@ -76,7 +78,7 @@ class TaskManager {
|
|||
this.add(new Task({
|
||||
name: 'CLEAN_UNUSED_TAGS',
|
||||
method: tagHelpers._cleanUnused,
|
||||
repeatDelay: day,
|
||||
repeatDelay: day+minute,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
@ -84,7 +86,15 @@ class TaskManager {
|
|||
this.add(new Task({
|
||||
name: 'CLEAN_FEDIVERSE_PAST_EVENT',
|
||||
method: apHelpers._cleanPastEvents,
|
||||
repeatDelay: day,
|
||||
repeatDelay: 6*hour+5*minute,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
||||
this.add(new Task({
|
||||
name: 'CLEAN_FEDIVERSE_AP_USERS',
|
||||
method: apHelpers._cleanUnusedAPUser,
|
||||
repeatDelay: day+10*minute,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
|
Loading…
Reference in a new issue