Add delay to profile updates to debounce them (#34137)

This commit is contained in:
Claire 2025-03-28 17:12:32 +01:00
parent 483b4600b5
commit 91ef24d0e3
12 changed files with 127 additions and 26 deletions

View file

@ -39,7 +39,25 @@ RSpec.describe 'credentials API' do
patch '/api/v1/accounts/update_credentials', headers: headers, params: params
end
let(:params) { { discoverable: true, locked: false, indexable: true } }
before do
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
end
let(:params) do
{
avatar: fixture_file_upload('avatar.gif', 'image/gif'),
discoverable: true,
display_name: "Alice Isn't Dead",
header: fixture_file_upload('attachment.jpg', 'image/jpeg'),
indexable: true,
locked: false,
note: 'Hello!',
source: {
privacy: 'unlisted',
sensitive: true,
},
}
end
it_behaves_like 'forbidden for wrong scope', 'read read:accounts'
@ -59,6 +77,27 @@ RSpec.describe 'credentials API' do
}),
locked: false,
})
expect(ActivityPub::UpdateDistributionWorker)
.to have_received(:perform_in).with(anything, user.account_id)
end
def expect_account_updates
expect(user.account.reload)
.to have_attributes(
display_name: eq("Alice Isn't Dead"),
note: 'Hello!',
avatar: exist,
header: exist
)
end
def expect_user_updates
expect(user.reload)
.to have_attributes(
setting_default_privacy: eq('unlisted'),
setting_default_sensitive: be(true)
)
end
end
end

View file

@ -16,7 +16,7 @@ RSpec.describe 'Deleting profile images' do
describe 'DELETE /api/v1/profile' do
before do
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
end
context 'when deleting an avatar' do
@ -48,12 +48,7 @@ RSpec.describe 'Deleting profile images' do
account.reload
expect(account.header).to exist
end
it 'queues up an account update distribution' do
delete '/api/v1/profile/avatar', headers: headers
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_in).with(anything, account.id)
end
end
@ -86,12 +81,7 @@ RSpec.describe 'Deleting profile images' do
account.reload
expect(account.header).to_not exist
end
it 'queues up an account update distribution' do
delete '/api/v1/profile/header', headers: headers
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_in).with(anything, account.id)
end
end
end