Agent Wranglers

In-app notifications Recommended

Delete old inbox items on a schedule

Delete inbox items after a fixed time, such as 90 days, and show the limit in the inbox.

How to do it

Old notifications hold personal data and slow the inbox query. Run a daily job that deletes in small batches, as in delete old data automatically. Keep read and unread items for the same time, so nothing piles up unseen. Say "Notifications are kept for 90 days" at the end of the list, and name the period in the privacy policy.

Example

DELETE FROM notifications
WHERE id IN (SELECT id FROM notifications WHERE created_at < now() - interval '90 days' LIMIT 1000);
const INBOX_RETENTION_DAYS = 90;
export async function pruneInbox() {
  let deleted;
  do deleted = await db.notifications.deleteOlderThan(INBOX_RETENTION_DAYS, { limit: 1000 });
  while (deleted === 1000);
}
INBOX_RETENTION_DAYS = 90

def prune_inbox():
    while db.notifications.delete_older_than(INBOX_RETENTION_DAYS, limit=1000) == 1000:
        pass

How to check

Insert a test row dated 91 days ago and run the job. The row is gone. A query finds no notification older than 90 days.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers notifications playbook: https://agentwranglers.se/playbook/notifications/in-app-notifications/inbox-retention.