From ed1da11c9df6334030f296a8e5a2ded5303ed156 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 14 Oct 2023 19:54:34 +0200 Subject: [PATCH] Add helper function to purge notifications --- lib/www/server/lib/db/notify.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/www/server/lib/db/notify.js b/lib/www/server/lib/db/notify.js index 4b364e9..0540ae8 100644 --- a/lib/www/server/lib/db/notify.js +++ b/lib/www/server/lib/db/notify.js @@ -1,6 +1,18 @@ const { makeSubscriber, pool } = require('./connection'); const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename); +async function purge () { + DEBUG("Purging old notifications"); + const client = await pool.connect(); + try { + await client.query("CALL purge_notifications();"); + } catch (err) { + ERROR(err); + } finally { + client.release(); + } +} + async function fullPayload (payload) { if (!payload.payload_id) { @@ -58,5 +70,6 @@ async function listen (addChannels, callback) { } module.exports = { - listen + listen, + purge };