Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
541a4cbb
Commit
541a4cbb
authored
Feb 24, 2018
by
lain
Browse files
Oh no! More fixes!
parent
01d5ef65
Pipeline
#819
failed with stage
in 2 minutes and 10 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/mix/tasks/fix_ap_users.ex
View file @
541a4cbb
...
...
@@ -14,7 +14,7 @@ def run([]) do
Enum
.
each
(
users
,
fn
(
user
)
->
IO
.
puts
(
"Fetching
#{
user
.
nickname
}
"
)
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
.
upgrade_user_from_ap_id
(
user
.
ap_id
)
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
.
upgrade_user_from_ap_id
(
user
.
ap_id
,
false
)
end
)
end
end
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
541a4cbb
...
...
@@ -197,31 +197,39 @@ def prepare_attachments(object) do
|>
Map
.
put
(
"attachment"
,
attachments
)
end
def
upgrade_user_from_ap_id
(
ap_id
)
do
defp
user_upgrade_task
(
user
)
do
old_follower_address
=
User
.
ap_followers
(
user
)
q
=
from
u
in
User
,
where:
^
old_follower_address
in
u
.
following
,
update:
[
set:
[
following:
fragment
(
"array_replace(?,?,?)"
,
u
.
following
,
^
old_follower_address
,
^
user
.
follower_address
)]]
Repo
.
update_all
(
q
,
[])
# Only do this for recent activties, don't go through the whole db.
since
=
(
Repo
.
aggregate
(
Activity
,
:max
,
:id
)
||
0
)
-
100_000
q
=
from
a
in
Activity
,
where:
^
old_follower_address
in
a
.
recipients
,
where:
a
.
id
>
^
since
,
update:
[
set:
[
recipients:
fragment
(
"array_replace(?,?,?)"
,
a
.
recipients
,
^
old_follower_address
,
^
user
.
follower_address
)]]
Repo
.
update_all
(
q
,
[])
end
def
upgrade_user_from_ap_id
(
ap_id
,
async
\\
true
)
do
with
%
User
{}
=
user
<-
User
.
get_by_ap_id
(
ap_id
),
{
:ok
,
data
}
<-
ActivityPub
.
fetch_and_prepare_user_from_ap_id
(
ap_id
)
do
data
=
data
|>
Map
.
put
(
:info
,
Map
.
merge
(
user
.
info
,
data
[
:info
]))
old_follower_address
=
User
.
ap_followers
(
user
)
{
:ok
,
user
}
=
User
.
upgrade_changeset
(
user
,
data
)
|>
Repo
.
update
()
# This could potentially take a long time, do it in the background
Task
.
start
(
fn
->
q
=
from
u
in
User
,
where:
^
old_follower_address
in
u
.
following
,
update:
[
set:
[
following:
fragment
(
"array_replace(?,?,?)"
,
u
.
following
,
^
old_follower_address
,
^
user
.
follower_address
)]]
Repo
.
update_all
(
q
,
[])
# Only do this for recent activties, don't go through the whole db.
since
=
(
Repo
.
aggregate
(
Activity
,
:max
,
:id
)
||
0
)
-
100_000
q
=
from
a
in
Activity
,
where:
^
old_follower_address
in
a
.
recipients
,
where:
a
.
id
>
^
since
,
update:
[
set:
[
recipients:
fragment
(
"array_replace(?,?,?)"
,
a
.
recipients
,
^
old_follower_address
,
^
user
.
follower_address
)]]
Repo
.
update_all
(
q
,
[])
end
)
if
async
do
Task
.
start
(
fn
->
user_upgrade_task
(
user
)
end
)
else
user_upgrade_task
(
user
)
end
{
:ok
,
user
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment