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