Fixed parameter binding in alert purge, added log.

This commit is contained in:
2026-07-13 19:53:13 +02:00
parent 2199bb3f39
commit 3007150aeb

View File

@@ -436,20 +436,20 @@ async function alertSceneReleases() {
}
async function purgeExpiredAlerts() {
await knex('notifications')
const purgedNotifications = await knex('notifications')
.where((builder) => {
builder
.where('seen', true)
.where((seenBuilder) => {
seenBuilder
.whereNull('seen_at') // marked seen before seen_at was added
.orWhereRaw('seen_at < now() - interval \'? days\'', [config.alerts.seenExpiry]);
.orWhereRaw('seen_at < now() - (?::int * interval \'1 day\')', [config.alerts.seenExpiry]); // '? day' would be interpreted literally
});
})
.orWhereRaw('created_at < now() - interval \'? days\'', [config.alerts.finalExpiry]) // don't accumulate notifications indefinitely
.orWhereRaw('created_at < now() - (?::int * interval \'1 day\')', [config.alerts.finalExpiry]) // don't accumulate notifications indefinitely
.delete();
await knex('alerts')
const purgedAlerts = await knex('alerts')
.where('is_expired', true)
.whereNotExists(
knex('notifications')
@@ -458,6 +458,8 @@ async function purgeExpiredAlerts() {
.delete();
await knex.schema.refreshMaterializedView('alerts_users_scenes');
logger.info(`Purged ${purgedNotifications} notifications and ${purgedAlerts} alerts`);
}
export function initAlertCron() {