Oh no! More fixes!
authorlain <lain@soykaf.club>
Sat, 24 Feb 2018 09:51:15 +0000 (10:51 +0100)
committerlain <lain@soykaf.club>
Sat, 24 Feb 2018 09:51:15 +0000 (10:51 +0100)
lib/mix/tasks/fix_ap_users.ex
lib/pleroma/web/activity_pub/transmogrifier.ex

index 09a2c0424704ffc3771abc840a6465dad6856520..a0038d5e826699315b109c5c78e145685bafe898 100644 (file)
@@ -14,7 +14,7 @@ defmodule Mix.Tasks.FixApUsers 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
index 62c2290500788d0b5681b0d01847c568138d7c1d..25c6bad06e5e04731ed22583f476ee5fb66a9cb7 100644 (file)
@@ -197,31 +197,39 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier 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