Skip to content

Fix notification generation logic to prevent duplicate notification#49

Merged
subsub97 merged 2 commits intomainfrom
fix/notification-overrap
Apr 9, 2026
Merged

Fix notification generation logic to prevent duplicate notification#49
subsub97 merged 2 commits intomainfrom
fix/notification-overrap

Conversation

@subsub97
Copy link
Copy Markdown
Collaborator

@subsub97 subsub97 commented Apr 9, 2026

This pull request updates the notification batch generation logic to prevent duplicate notifications for the same member and date, and simplifies the code by removing redundant checks. The main changes include replacing broad "already generated" checks with more granular member-level filtering, updating repository methods, and cleaning up unused code.

Notification generation logic improvements:

  • The logic for checking if notifications have already been generated is now performed per member, preventing duplicate notifications for individual members rather than skipping the entire batch for a date. This is done by fetching already-notified member IDs and filtering them out before generating new notifications in NotificationBatchService and PaydayNotificationBatchService. [1] [2] [3]
  • The previous isAlreadyGenerated methods and their associated repository methods have been removed, as they are no longer needed with the new per-member approach. [1] [2] [3]

Repository changes:

  • The NotificationLogRepository interface has been updated: the old existsByScheduledDateAndNotificationType and existsByMemberIdAndScheduledDateAndStatus methods were removed, and a new findMemberIdsByScheduledDateAndNotificationType method was added to return a list of member IDs for a given date and notification type.
  • The necessary import for @Query was added to support the new repository method.

Code cleanup:

  • Minor import order adjustments were made for consistency in NotificationBatchService.…ions for public holidays and paydays

Copilot AI review requested due to automatic review settings April 9, 2026 14:33
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Test Results

53 tests   53 ✅  0s ⏱️
 6 suites   0 💤
 6 files     0 ❌

Results for commit ddb0e70.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates notification batch generation to avoid creating duplicate notification logs for the same member/date by switching from date-wide “already generated” checks to per-member filtering, and adjusts the notification log repository API accordingly.

Changes:

  • Filter target members/profiles by excluding memberIds that already have logs for the same scheduledDate + notificationType.
  • Remove the old isAlreadyGenerated(...) logic from batch services.
  • Replace repository “exists” checks with a query that returns memberIds already notified for a given date/type.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/main/kotlin/com/moa/service/notification/NotificationBatchService.kt Applies member-level filtering for CLOCK_IN and PUBLIC_HOLIDAY generation and removes date-wide guard.
src/main/kotlin/com/moa/service/notification/PaydayNotificationBatchService.kt Applies member-level filtering for PAYDAY generation and removes date-wide guard.
src/main/kotlin/com/moa/repository/NotificationLogRepository.kt Replaces boolean “exists” APIs with a JPQL query returning memberIds for scheduledDate + notificationType.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +45
@Query(
"select n.memberId " +
"from NotificationLog n " +
"where n.scheduledDate = :scheduledDate and n.notificationType = :notificationType"
)
fun findMemberIdsByScheduledDateAndNotificationType(
scheduledDate: LocalDate,
notificationType: NotificationType,
): Boolean
): List<Long>
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JPQL query can return duplicate memberIds if there are multiple NotificationLog rows for the same member/date/type (e.g., retries). Since callers immediately convert to a Set, consider changing the query to select distinct n.memberId to reduce DB row count and network/memory usage. If possible, also consider narrowing the query by candidate memberIds (IN clause), since the services already have the member list and only need the intersection.

Copilot uses AI. Check for mistakes.
@subsub97 subsub97 merged commit 2df9a60 into main Apr 9, 2026
3 checks passed
@subsub97 subsub97 deleted the fix/notification-overrap branch April 9, 2026 15:04
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.

2 participants