Skip to content

Commit

Permalink
feat(notification): auto deletion of old notifications after 2 months
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarseguerra committed Oct 24, 2024
1 parent 4459fb0 commit e61346a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/services/NotificationService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const NameService = require('./NameService');
const CommonService = require('./CommonService');

const NOTIFICATION_ENTITIES = {
CAVE: 'cave',
Expand All @@ -22,6 +23,11 @@ const NOTIFICATION_TYPES = {
RESTORE: 'RESTORE',
};

async function removeOlderNotifications() {
const query = `DELETE FROM t_notification WHERE date_inscription < current_timestamp - interval '2 month';`;
await CommonService.query(query);
}

const safeGetPropId = (prop, data) => {
if (data && data[prop]) {
if (data[prop] instanceof Object) {
Expand Down Expand Up @@ -470,6 +476,11 @@ module.exports = {
return true;
})
);

// 5% chance to also remove older notifications
if (process.env.NODE_ENV !== 'test' && Math.random() < 0.05)
removeOlderNotifications();

return res;
} catch (error) {
// Fail silently to avoid sending an error to the user
Expand Down

0 comments on commit e61346a

Please sign in to comment.