Commit efd4d049 authored by lain's avatar lain

Fix user upgrading code.

parent 1331a39d
Pipeline #817 failed with stage
in 2 minutes and 19 seconds
...@@ -209,15 +209,18 @@ def upgrade_user_from_ap_id(ap_id) do ...@@ -209,15 +209,18 @@ def upgrade_user_from_ap_id(ap_id) do
# This could potentially take a long time, do it in the background # This could potentially take a long time, do it in the background
Task.start(fn -> Task.start(fn ->
q = from a in Activity,
where: ^old_follower_address in a.recipients,
update: [set: [recipients: fragment("array_replace(?,?,?)", a.recipients, ^old_follower_address, ^user.follower_address)]]
Repo.update_all(q, [])
q = from u in User, q = from u in User,
where: ^old_follower_address in u.following, where: ^old_follower_address in u.following,
update: [set: [following: fragment("array_replace(?,?,?)", u.following, ^old_follower_address, ^user.follower_address)]] update: [set: [following: fragment("array_replace(?,?,?)", u.following, ^old_follower_address, ^user.follower_address)]]
Repo.update_all(q, []) 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) end)
{:ok, user} {:ok, user}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment