close
Skip to content

[2.x] fix(notifications): invalidate unread count cache on delete all#4390

Merged
imorland merged 1 commit into2.xfrom
im/fix-delete-notifications-cache-invalidation
Feb 26, 2026
Merged

[2.x] fix(notifications): invalidate unread count cache on delete all#4390
imorland merged 1 commit into2.xfrom
im/fix-delete-notifications-cache-invalidation

Conversation

@imorland
Copy link
Copy Markdown
Member

Regression of #4380

#4380 added 5-minute caching to getUnreadNotificationCount() and getNewNotificationCount() with active cache invalidation in:

  • ReadNotificationHandler
  • ReadAllNotificationsHandler
  • NotificationResource (index) ✅
  • Notification::notify()
  • DeleteAllNotificationsHandler ❌ — missed

Symptom

After clicking "Delete All" in the notifications dropdown, the notifications disappear from the list (optimistic update works) but the unread count badge on the bell icon reappears on the next page load or any API response that includes the user's counts — and stays wrong for up to 5 minutes until the cache naturally expires.

This did not occur in v1.x because notification count caching was introduced in 2.x via #4380.

Fix

Inject CacheRepository into DeleteAllNotificationsHandler and call forget() on both count keys after deletion — identical pattern to ReadAllNotificationsHandler.

Test

Added a regression test to DeleteTest that:

  1. Primes both cache keys with a stale value of 99
  2. Sends DELETE /api/notifications
  3. Asserts both cache keys are null after the request

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

…ession of #4380)

#4380 added caching to getUnreadNotificationCount() and getNewNotificationCount()
and correctly invalidated the cache in ReadAllNotificationsHandler and
ReadNotificationHandler. DeleteAllNotificationsHandler was missed, so deleting
all notifications left the stale count in the cache for up to 5 minutes —
causing the notification badge to reappear after deletion until the cache
naturally expired.

Fix: inject CacheRepository and call forget() on both count keys after deletion,
matching the pattern already used in ReadAllNotificationsHandler.

Also adds a regression test that primes the cache with a stale count, calls
DELETE /notifications, and asserts both cache keys are cleared.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imorland imorland requested a review from a team as a code owner February 26, 2026 10:28
@imorland imorland changed the title fix(notifications): invalidate unread count cache on delete all [2.x] fix(notifications): invalidate unread count cache on delete all Feb 26, 2026
@imorland imorland added this to the 2.0.0-beta.8 milestone Feb 26, 2026
@imorland imorland merged commit 8e7364f into 2.x Feb 26, 2026
35 checks passed
@imorland imorland deleted the im/fix-delete-notifications-cache-invalidation branch February 26, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant