Fixed parameter binding in alert purge, added log.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user