Fix notification generation logic to prevent duplicate notification#49
Fix notification generation logic to prevent duplicate notification#49
Conversation
…ions for public holidays and paydays
Test Results53 tests 53 ✅ 0s ⏱️ Results for commit ddb0e70. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
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.
| @Query( | ||
| "select n.memberId " + | ||
| "from NotificationLog n " + | ||
| "where n.scheduledDate = :scheduledDate and n.notificationType = :notificationType" | ||
| ) | ||
| fun findMemberIdsByScheduledDateAndNotificationType( | ||
| scheduledDate: LocalDate, | ||
| notificationType: NotificationType, | ||
| ): Boolean | ||
| ): List<Long> |
There was a problem hiding this comment.
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.
…for public holidays and paydays
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:
NotificationBatchServiceandPaydayNotificationBatchService. [1] [2] [3]isAlreadyGeneratedmethods 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:
NotificationLogRepositoryinterface has been updated: the oldexistsByScheduledDateAndNotificationTypeandexistsByMemberIdAndScheduledDateAndStatusmethods were removed, and a newfindMemberIdsByScheduledDateAndNotificationTypemethod was added to return a list of member IDs for a given date and notification type.@Querywas added to support the new repository method.Code cleanup:
NotificationBatchService.…ions for public holidays and paydays