Remove deprecated single-argument variation of UnfilterNotificationsWorker

This commit is contained in:
Matt Jankowski 2024-12-18 10:33:23 -05:00
parent 839a4e27a9
commit e4d9e643ba
2 changed files with 15 additions and 30 deletions

View File

@ -4,25 +4,14 @@ class UnfilterNotificationsWorker
include Sidekiq::Worker
include Redisable
# Earlier versions of the feature passed a `notification_request` ID
# If `to_account_id` is passed, the first argument is an account ID
# TODO for after 4.3.0: drop the single-argument case
def perform(notification_request_or_account_id, from_account_id = nil)
if from_account_id.present?
@notification_request = nil
def perform(account_id, from_account_id)
@from_account = Account.find_by(id: from_account_id)
@recipient = Account.find_by(id: notification_request_or_account_id)
else
@notification_request = NotificationRequest.find_by(id: notification_request_or_account_id)
@from_account = @notification_request&.from_account
@recipient = @notification_request&.account
end
@recipient = Account.find_by(id: account_id)
return if @from_account.nil? || @recipient.nil?
push_to_conversations!
unfilter_notifications!
remove_request!
decrement_worker_count!
end
@ -36,10 +25,6 @@ class UnfilterNotificationsWorker
filtered_notifications.in_batches.update_all(filtered: false)
end
def remove_request!
@notification_request&.destroy!
end
def filtered_notifications
Notification.where(account: @recipient, from_account: @from_account, filtered: true)
end

View File

@ -5,6 +5,7 @@ require 'rails_helper'
RSpec.describe UnfilterNotificationsWorker do
let(:recipient) { Fabricate(:account) }
let(:sender) { Fabricate(:account) }
let(:worker) { described_class.new }
before do
# Populate multiple kinds of filtered notifications
@ -67,23 +68,22 @@ RSpec.describe UnfilterNotificationsWorker do
end
describe '#perform' do
context 'with single argument (prerelease behavior)' do
subject { described_class.new.perform(notification_request.id) }
let(:notification_request) { Fabricate(:notification_request, from_account: sender, account: recipient) }
it_behaves_like 'shared behavior'
it 'destroys the notification request' do
expect { subject }
.to change { NotificationRequest.exists?(notification_request.id) }.to(false)
end
end
context 'with two arguments' do
subject { described_class.new.perform(recipient.id, sender.id) }
context 'with recipient and sender' do
subject { worker.perform(recipient.id, sender.id) }
it_behaves_like 'shared behavior'
end
context 'with missing records' do
it 'runs without error for missing sender' do
expect { worker.perform(recipient.id, nil) }
.to_not raise_error
end
it 'runs without error for missing recipient' do
expect { worker.perform(nil, sender.id) }
.to_not raise_error
end
end
end
end