Skip to content

Conversation

@rohithgowda18
Copy link

Fixes #13325

Problem

Users were receiving duplicate streak achievement notifications (often 2-3 identical notifications) when earning a streak milestone. Each duplicate had to be dismissed separately, causing UX friction.

Reported behavior:

  • ~95% of the time, users see 2+ notifications for the same streak achievement
  • Example: "streak achievement 528" appears twice with different notification IDs
  • When earning multiple streaks on the same day, each can duplicate (4 notifications total)

Root Cause

The issue occurs at two levels:

  1. Server-side: No deduplication logic for STREAK_ACHIEVEMENT notifications in the cleanup process
  2. Client-side: Notifications tracked only by ID, so duplicates with different IDs both display

Solution

Server-Side Fix (website/server/models/userNotification.js)

  • Added deduplication logic in cleanupCorruptData() function
  • Uses _.uniqWith() to remove duplicate STREAK_ACHIEVEMENT notifications
  • Follows existing pattern used for NEW_CHAT_MESSAGE deduplication
  • Prevents duplicates from reaching the client

Client-Side Fix (website/client/src/components/notifications.vue)

  • Added lastShownStreakCount property to track displayed streak achievements
  • Checks user.achievements.streak before showing notification
  • Provides defensive protection even if server sends duplicates
  • Maintains backward compatibility with existing notification flow

Testing (test/api/unit/models/userNotification.test.js)

  • Added 2 comprehensive test cases for STREAK_ACHIEVEMENT deduplication
  • Ensures fix doesn't affect other notification types
  • Validates existing NEW_CHAT_MESSAGE deduplication still works

Changes

  • Modified: website/server/models/userNotification.js - Server-side deduplication
  • Modified: website/client/src/components/notifications.vue - Client-side duplicate prevention
  • Modified: test/api/unit/models/userNotification.test.js - Added unit tests
  • Added: DUPLICATE_STREAK_FIX.md - Implementation documentation

Testing Instructions

  1. Run unit tests: npm test test/api/unit/models/userNotification.test.js
  2. Manual testing:
    • Complete a daily task that achieves a 21-day streak milestone
    • Verify only ONE notification appears
    • Check notification can be dismissed with single click

Impact

  • ✅ Prevents duplicate notifications at both server and client level
  • ✅ No breaking changes to existing notification system
  • ✅ Minimal performance impact (uses existing cleanup process)
  • ✅ Backward compatible with older notification data

UUID: c2669fd4-edcb-4757-98d6-31d239ce6abe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

streak achievement appearing twice

1 participant