Repository navigation
fix: only decrease the notification red dot cache once per notification - #1644
Merged
Merged
Conversation
Marking a notification as read is a no-op in the database when it is already read, but ClearIDUnRead decreased the cached red dot count unconditionally. Duplicate sequential requests therefore decreased the counter twice: the first request changed the notification from unread to read, while the second skipped the meaningful database transition but still decreased the cache. Two concurrent requests could do the same, because the update had no "is_read = unread" predicate and the changed row count was discarded. Make the update conditional and atomic (WHERE user_id = ? AND id = ? AND is_read = unread) and only decrease the cache counter when exactly one row was changed. The badge award alert cache cleanup stays independent, since it is already idempotent. Close apache#1643
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1643
As suggested in the issue, marking a notification as read is now conditional and atomic, and the red dot cache is only decreased when the notification really changed from unread to read.
Proposed Changes
ClearIDUnReadin the notification repository adds anis_read = unreadpredicate to the update and returns the number of changed rows, whichxormalready provided but was discarded.NotificationService.ClearIDUnReadonly callsDecreaseRedDotwhen exactly one row was changed, so duplicate sequential requests and concurrent duplicate requests for the same notification cannot decrease the cached counter more than once. The badge award alert cache cleanup stays independent, since it is already idempotent.ClearUnRead(mark all as read) is intentionally not touched: as noted in the issue, the red dot cache is not designed as an exact mirror of the unread rows, so the fix is scoped to making the single-notification read endpoint idempotent.