fix: remote events removal

This commit is contained in:
lesion 2024-01-21 23:13:41 +01:00
parent a7f7fe3ecf
commit 742ed44534
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 6 additions and 3 deletions

View file

@ -11,7 +11,7 @@ const Col = helpers.col
const notifier = require('../../notifier')
const { htmlToText } = require('html-to-text')
const { Event, Resource, Tag, Place, Notification, APUser, Collection } = require('../models/models')
const { Event, Resource, Tag, Place, Notification, APUser, Collection, EventNotification } = require('../models/models')
const exportController = require('./export')
@ -586,6 +586,7 @@ const eventController = {
try {
// remove related resources
await Resource.destroy({ where: { eventId: event.id }})
await EventNotification.destroy({ where: { eventId: event.id }})
// and finally remove the event
await event.destroy()

View file

@ -1,4 +1,4 @@
const { Event, Resource } = require('../api/models/models')
const { Event, Resource, EventNotification } = require('../api/models/models')
const { Op } = require('sequelize')
const { DateTime } = require('luxon')
const log = require('../log')
@ -9,13 +9,15 @@ module.exports = {
const events = await Event.findAll({ where: {
start_datetime: { [Op.lt]: now },
apUserApId: { [Op.ne]: null }
}})
}, raw: true })
if (!events.length) { return }
log.info(`Remove ${events.length} past federated events and related resources`)
await Resource.destroy({ where: { eventId: events.map(e => e.id) }})
await EventNotification.destroy({ where: { eventId: events.map(e => e.id) }})
await Event.destroy({
where: {
start_datetime: { [Op.lt]: now },