mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-12 07:16:04 -05:00
Fix notifications not being cleaned up when notification requests are deleted in bulk (#40393)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user