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() { async function purgeExpiredAlerts() {
await knex('notifications') const purgedNotifications = await knex('notifications')
.where((builder) => { .where((builder) => {
builder builder
.where('seen', true) .where('seen', true)
.where((seenBuilder) => { .where((seenBuilder) => {
seenBuilder seenBuilder
.whereNull('seen_at') // marked seen before seen_at was added .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(); .delete();
await knex('alerts') const purgedAlerts = await knex('alerts')
.where('is_expired', true) .where('is_expired', true)
.whereNotExists( .whereNotExists(
knex('notifications') knex('notifications')
@@ -458,6 +458,8 @@ async function purgeExpiredAlerts() {
.delete(); .delete();
await knex.schema.refreshMaterializedView('alerts_users_scenes'); await knex.schema.refreshMaterializedView('alerts_users_scenes');
logger.info(`Purged ${purgedNotifications} notifications and ${purgedAlerts} alerts`);
} }
export function initAlertCron() { export function initAlertCron() {