Fix notifications not being cleaned up when notification requests are deleted in bulk (#40393)

This commit is contained in:
Claire
2026-09-07 09:29:42 +00:00
committed by GitHub
parent 0d102fb2da
commit baab7b8768
4 changed files with 21 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
end
def dismiss_bulk
FilteredNotificationCleanupWorker.perform_async(current_account.id, @requests.map(&:from_account_id))
@requests.each(&:destroy!)
render_empty
end

View File

@@ -3,7 +3,7 @@
class FilteredNotificationCleanupWorker
include Sidekiq::Worker
def perform(account_id, from_account_id)
Notification.where(account_id: account_id, from_account_id: from_account_id, filtered: true).in_batches(order: :desc).delete_all
def perform(account_id, from_account_ids)
Notification.where(account_id: account_id, from_account_id: from_account_ids, filtered: true).in_batches(order: :desc).delete_all
end
end

View File

@@ -122,7 +122,9 @@ RSpec.describe 'Requests' do
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
it 'returns http success and destroys the notification request', :aggregate_failures do
expect { subject }.to change(NotificationRequest, :count).by(-1)
expect { subject }
.to change(NotificationRequest, :count).by(-1)
.and enqueue_sidekiq_job(FilteredNotificationCleanupWorker).with(user.account_id, be_a(Array))
expect(response).to have_http_status(200)
expect(response.content_type)

View File

@@ -20,5 +20,20 @@ RSpec.describe FilteredNotificationCleanupWorker do
.to change { recipient.notifications.where(from_account: sender).count }.from(2).to(0)
.and(not_change { recipient.notifications.where(from_account: bystander).count })
end
context 'when given an array of IDs as parameter' do
let(:other_sender) { Fabricate(:account) }
before do
Fabricate(:notification, account: recipient, activity: Fabricate(:favourite, account: other_sender), filtered: true)
end
it 'deletes all filtered notifications to the account' do
expect { described_class.new.perform(recipient.id, [sender.id, other_sender.id]) }
.to change { recipient.notifications.where(from_account: sender).count }.from(2).to(0)
.and change { recipient.notifications.where(from_account: other_sender).count }.from(1).to(0)
.and(not_change { recipient.notifications.where(from_account: bystander).count })
end
end
end
end