Skip to content

Commit ad3407a

Browse files
Gargronhiyuki2578
authored andcommitted
Fix Move handler queuing jobs that will fail if account is suspended (mastodon#11864)
Don't put Move handler on cooldown if it didn't run. Skip unmerging from timelines to save unnecessary work.
1 parent 52c889a commit ad3407a

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

app/lib/activitypub/activity/move.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ def perform
1010

1111
target_account = ActivityPub::FetchRemoteAccountService.new.call(target_uri)
1212

13-
return if target_account.nil? || !target_account.also_known_as.include?(origin_account.uri)
13+
if target_account.nil? || target_account.suspended? || !target_account.also_known_as.include?(origin_account.uri)
14+
unmark_as_processing!
15+
return
16+
end
1417

1518
# In case for some reason we didn't have a redirect for the profile already, set it
16-
origin_account.update(moved_to_account: target_account) if origin_account.moved_to_account_id.nil?
19+
origin_account.update(moved_to_account: target_account)
1720

1821
# Initiate a re-follow for each follower
1922
origin_account.followers.local.select(:id).find_in_batches do |follower_accounts|
@@ -40,4 +43,8 @@ def processed?
4043
def mark_as_processing!
4144
redis.setex("move_in_progress:#{@account.id}", PROCESSING_COOLDOWN, true)
4245
end
46+
47+
def unmark_as_processing!
48+
redis.del("move_in_progress:#{@account.id}")
49+
end
4350
end

app/services/unfollow_service.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ class UnfollowService < BaseService
66
# Unfollow and notify the remote user
77
# @param [Account] source_account Where to unfollow from
88
# @param [Account] target_account Which to unfollow
9-
def call(source_account, target_account)
9+
# @param [Hash] options
10+
# @option [Boolean] :skip_unmerge
11+
def call(source_account, target_account, options = {})
1012
@source_account = source_account
1113
@target_account = target_account
14+
@options = options
1215

1316
unfollow! || undo_follow_request!
1417
end
@@ -21,9 +24,11 @@ def unfollow!
2124
return unless follow
2225

2326
follow.destroy!
27+
2428
create_notification(follow) if !@target_account.local? && @target_account.activitypub?
2529
create_reject_notification(follow) if @target_account.local? && !@source_account.local? && @source_account.activitypub?
26-
UnmergeWorker.perform_async(@target_account.id, @source_account.id)
30+
UnmergeWorker.perform_async(@target_account.id, @source_account.id) unless @options[:skip_unmerge]
31+
2732
follow
2833
end
2934

@@ -33,7 +38,9 @@ def undo_follow_request!
3338
return unless follow_request
3439

3540
follow_request.destroy!
41+
3642
create_notification(follow_request) unless @target_account.local?
43+
3744
follow_request
3845
end
3946

app/workers/unfollow_follow_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def perform(follower_account_id, old_target_account_id, new_target_account_id)
1111
new_target_account = Account.find(new_target_account_id)
1212

1313
FollowService.new.call(follower_account, new_target_account)
14-
UnfollowService.new.call(follower_account, old_target_account)
14+
UnfollowService.new.call(follower_account, old_target_account, skip_unmerge: true)
1515
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
1616
true
1717
end

0 commit comments

Comments
 (0)