Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
c98b0125
Unverified
Commit
c98b0125
authored
1 year ago
by
Claire
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Change Move handler to also move list memberships (#24808)
parent
9a52a7f7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/services/follow_migration_service.rb
+14
-4
14 additions, 4 deletions
app/services/follow_migration_service.rb
app/workers/move_worker.rb
+11
-5
11 additions, 5 deletions
app/workers/move_worker.rb
spec/workers/move_worker_spec.rb
+29
-7
29 additions, 7 deletions
spec/workers/move_worker_spec.rb
with
54 additions
and
16 deletions
app/services/follow_migration_service.rb
+
14
−
4
View file @
c98b0125
...
...
@@ -9,10 +9,10 @@ class FollowMigrationService < FollowService
def
call
(
source_account
,
target_account
,
old_target_account
,
bypass_locked:
false
)
@old_target_account
=
old_target_account
follow
=
source_account
.
active_relationships
.
find_by
(
target_account:
old_target_account
)
reblogs
=
follow
&
.
show_reblogs?
notify
=
follow
&
.
notify?
languages
=
follow
&
.
languages
@original_
follow
=
source_account
.
active_relationships
.
find_by
(
target_account:
old_target_account
)
reblogs
=
@original_
follow
&
.
show_reblogs?
notify
=
@original_
follow
&
.
notify?
languages
=
@original_
follow
&
.
languages
super
(
source_account
,
target_account
,
reblogs:
reblogs
,
notify:
notify
,
languages:
languages
,
bypass_locked:
bypass_locked
,
bypass_limit:
true
)
end
...
...
@@ -21,6 +21,7 @@ class FollowMigrationService < FollowService
def
request_follow!
follow_request
=
@source_account
.
request_follow!
(
@target_account
,
**
follow_options
.
merge
(
rate_limit:
@options
[
:with_rate_limit
],
bypass_limit:
@options
[
:bypass_limit
]))
migrate_list_accounts!
if
@target_account
.
local?
LocalNotificationWorker
.
perform_async
(
@target_account
.
id
,
follow_request
.
id
,
follow_request
.
class
.
name
,
'follow_request'
)
...
...
@@ -34,7 +35,16 @@ class FollowMigrationService < FollowService
def
direct_follow!
follow
=
super
migrate_list_accounts!
UnfollowService
.
new
.
call
(
@source_account
,
@old_target_account
,
skip_unmerge:
true
)
follow
end
def
migrate_list_accounts!
ListAccount
.
where
(
follow_id:
@original_follow
.
id
).
includes
(
:list
).
find_each
do
|
list_account
|
list_account
.
list
.
accounts
<<
@target_account
end
end
end
This diff is collapsed.
Click to expand it.
app/workers/move_worker.rb
+
11
−
5
View file @
c98b0125
...
...
@@ -8,9 +8,9 @@ class MoveWorker
@target_account
=
Account
.
find
(
target_account_id
)
if
@target_account
.
local?
&&
@source_account
.
local?
n
b
_moved
=
rewrite_follows!
@source_account
.
update_count!
(
:followers_count
,
-
n
b
_moved
)
@target_account
.
update_count!
(
:followers_count
,
n
b
_moved
)
n
um
_moved
=
rewrite_follows!
@source_account
.
update_count!
(
:followers_count
,
-
n
um
_moved
)
@target_account
.
update_count!
(
:followers_count
,
n
um
_moved
)
else
queue_follow_unfollows!
end
...
...
@@ -29,12 +29,18 @@ class MoveWorker
private
def
rewrite_follows!
num_moved
=
0
@source_account
.
passive_relationships
.
where
(
account:
Account
.
local
)
.
where
.
not
(
account:
@target_account
.
followers
.
local
)
.
where
.
not
(
account_id:
@target_account
.
id
)
.
in_batches
.
update_all
(
target_account_id:
@target_account
.
id
)
.
in_batches
do
|
follows
|
ListAccount
.
where
(
follow:
follows
).
in_batches
.
update_all
(
account_id:
@target_account
.
id
)
num_moved
+=
follows
.
update_all
(
target_account_id:
@target_account
.
id
)
end
num_moved
end
def
queue_follow_unfollows!
...
...
This diff is collapsed.
Click to expand it.
spec/workers/move_worker_spec.rb
+
29
−
7
View file @
c98b0125
...
...
@@ -5,22 +5,28 @@ require 'rails_helper'
describe
MoveWorker
do
subject
{
described_class
.
new
}
let
(
:local_follower
)
{
Fabricate
(
:account
)
}
let
(
:local_follower
)
{
Fabricate
(
:account
,
domain:
nil
)
}
let
(
:blocking_account
)
{
Fabricate
(
:account
)
}
let
(
:muting_account
)
{
Fabricate
(
:account
)
}
let
(
:source_account
)
{
Fabricate
(
:account
,
protocol: :activitypub
,
domain:
'example.com'
)
}
let
(
:target_account
)
{
Fabricate
(
:account
,
protocol: :activitypub
,
domain:
'example.com'
)
}
let
(
:source_account
)
{
Fabricate
(
:account
,
protocol: :activitypub
,
domain:
'example.com'
,
uri:
'https://example.org/a'
,
inbox_url:
'https://example.org/a/inbox'
)
}
let
(
:target_account
)
{
Fabricate
(
:account
,
protocol: :activitypub
,
domain:
'example.com'
,
uri:
'https://example.org/b'
,
inbox_url:
'https://example.org/b/inbox'
)
}
let
(
:local_user
)
{
Fabricate
(
:user
)
}
let
(
:comment
)
{
'old note prior to move'
}
let!
(
:account_note
)
{
Fabricate
(
:account_note
,
account:
local_user
.
account
,
target_account:
source_account
,
comment:
comment
)
}
let
(
:list
)
{
Fabricate
(
:list
,
account:
local_follower
)
}
let
(
:block_service
)
{
double
}
before
do
stub_request
(
:post
,
'https://example.org/a/inbox'
).
to_return
(
status:
200
)
stub_request
(
:post
,
'https://example.org/b/inbox'
).
to_return
(
status:
200
)
local_follower
.
follow!
(
source_account
)
blocking_account
.
block!
(
source_account
)
muting_account
.
mute!
(
source_account
)
list
.
accounts
<<
source_account
allow
(
BlockService
).
to
receive
(
:new
).
and_return
(
block_service
)
allow
(
block_service
).
to
receive
(
:call
)
end
...
...
@@ -86,16 +92,27 @@ describe MoveWorker do
end
end
shared_examples
'lists handling'
do
it
'updates lists'
do
subject
.
perform
(
source_account
.
id
,
target_account
.
id
)
expect
(
list
.
accounts
.
include?
(
target_account
)).
to
be
true
end
end
context
'both accounts are distant'
do
describe
'perform'
do
it
'calls UnfollowFollowWorker'
do
expect_push_bulk_to_match
(
UnfollowFollowWorker
,
[[
local_follower
.
id
,
source_account
.
id
,
target_account
.
id
,
false
]])
subject
.
perform
(
source_account
.
id
,
target_account
.
id
)
Sidekiq
::
Testing
.
fake!
do
subject
.
perform
(
source_account
.
id
,
target_account
.
id
)
expect
(
UnfollowFollowWorker
).
to
have_enqueued_sidekiq_job
(
local_follower
.
id
,
source_account
.
id
,
target_account
.
id
,
false
)
Sidekiq
::
Worker
.
drain_all
end
end
include_examples
'user note handling'
include_examples
'block and mute handling'
include_examples
'followers count handling'
include_examples
'lists handling'
end
end
...
...
@@ -104,13 +121,17 @@ describe MoveWorker do
describe
'perform'
do
it
'calls UnfollowFollowWorker'
do
expect_push_bulk_to_match
(
UnfollowFollowWorker
,
[[
local_follower
.
id
,
source_account
.
id
,
target_account
.
id
,
true
]])
subject
.
perform
(
source_account
.
id
,
target_account
.
id
)
Sidekiq
::
Testing
.
fake!
do
subject
.
perform
(
source_account
.
id
,
target_account
.
id
)
expect
(
UnfollowFollowWorker
).
to
have_enqueued_sidekiq_job
(
local_follower
.
id
,
source_account
.
id
,
target_account
.
id
,
true
)
Sidekiq
::
Worker
.
clear_all
end
end
include_examples
'user note handling'
include_examples
'block and mute handling'
include_examples
'followers count handling'
include_examples
'lists handling'
end
end
...
...
@@ -127,6 +148,7 @@ describe MoveWorker do
include_examples
'user note handling'
include_examples
'block and mute handling'
include_examples
'followers count handling'
include_examples
'lists handling'
it
'does not fail when a local user is already following both accounts'
do
double_follower
=
Fabricate
(
:account
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment