chore: Get all notification API improvments (#8549)

Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
Muhsin Keloth
2024-01-17 09:02:18 +05:30
committed by GitHub
parent e67f8824d9
commit 818424259f
10 changed files with 176 additions and 31 deletions

View File

@@ -7,10 +7,11 @@ class Notification::RemoveDuplicateNotificationJob < ApplicationJob
user_id = notification.user_id
primary_actor_id = notification.primary_actor_id
# Find older notifications with the same user and primary_actor_id, excluding the new one
# Find older notifications with the same user and primary_actor_id
duplicate_notifications = Notification.where(user_id: user_id, primary_actor_id: primary_actor_id)
.where.not(id: notification.id)
.order(created_at: :desc)
duplicate_notifications.each(&:destroy)
# Skip the first one (the latest notification) and destroy the rest
duplicate_notifications.offset(1).each(&:destroy)
end
end