Skip to content

Commit

Permalink
Fix followers count not being updated when migrating follows (mastodo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Nov 7, 2022
1 parent a70e2cd commit 5925a31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/workers/move_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def perform(source_account_id, target_account_id)
@target_account = Account.find(target_account_id)

if @target_account.local? && @source_account.local?
rewrite_follows!
nb_moved = rewrite_follows!
@source_account.update_count!(:followers_count, -nb_moved)
@target_account.update_count!(:followers_count, nb_moved)
else
queue_follow_unfollows!
end
Expand Down
15 changes: 15 additions & 0 deletions spec/workers/move_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
end
end

shared_examples 'followers count handling' do
it 'updates the source account followers count' do
subject.perform(source_account.id, target_account.id)
expect(source_account.reload.followers_count).to eq(source_account.passive_relationships.count)
end

it 'updates the target account followers count' do
subject.perform(source_account.id, target_account.id)
expect(target_account.reload.followers_count).to eq(target_account.passive_relationships.count)
end
end

context 'both accounts are distant' do
describe 'perform' do
it 'calls UnfollowFollowWorker' do
Expand All @@ -83,6 +95,7 @@

include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'
end
end

Expand All @@ -97,6 +110,7 @@

include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'
end
end

Expand All @@ -112,6 +126,7 @@

include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'

it 'does not fail when a local user is already following both accounts' do
double_follower = Fabricate(:account)
Expand Down

0 comments on commit 5925a31

Please sign in to comment.