From 8228ae96d87fa9a8dc6c2603767ab8f094703e9e Mon Sep 17 00:00:00 2001
From: lain <lain@soykaf.club>
Date: Wed, 7 Mar 2018 20:19:48 +0100
Subject: [PATCH] Only run the fix-up tasks once.

---
 lib/pleroma/web/activity_pub/transmogrifier.ex | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 54468b5f9..37db67798 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -266,16 +266,19 @@ def upgrade_user_from_ap_id(ap_id, async \\ true) do
       data = data
       |> Map.put(:info, Map.merge(user.info, data[:info]))
 
+      already_ap = User.ap_enabled?(user)
       {:ok, user} = User.upgrade_changeset(user, data)
       |> Repo.update()
 
-      # This could potentially take a long time, do it in the background
-      if async do
-        Task.start(fn ->
+      if !already_ap do
+        # This could potentially take a long time, do it in the background
+        if async do
+          Task.start(fn ->
+            user_upgrade_task(user)
+          end)
+        else
           user_upgrade_task(user)
-        end)
-      else
-        user_upgrade_task(user)
+        end
       end
 
       {:ok, user}