Fix user upgrading code.
authorlain <lain@soykaf.club>
Sat, 24 Feb 2018 09:28:38 +0000 (10:28 +0100)
committerlain <lain@soykaf.club>
Sat, 24 Feb 2018 09:28:38 +0000 (10:28 +0100)
lib/pleroma/web/activity_pub/transmogrifier.ex

index a3bbae2a5eebb738ed30a4f3f008ae42e1e74b0d..fcf3804d50328191deaeb810b5f9634594990846 100644 (file)
@@ -209,15 +209,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
 
       # This could potentially take a long time, do it in the background
       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,
         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)
 
       {:ok, user}