Deletions: purge the user immediately
authorAlex Gleason <alex@alexgleason.me>
Wed, 30 Jun 2021 03:30:48 +0000 (22:30 -0500)
committerAlex Gleason <alex@alexgleason.me>
Wed, 30 Jun 2021 03:30:48 +0000 (22:30 -0500)
lib/pleroma/user.ex

index aebb5da956c2b8a41eb01af510d769e963c9e78b..406a7f5f99b9b4ef772a0782a8318d2247f6171b 100644 (file)
@@ -1724,31 +1724,27 @@ defmodule Pleroma.User do
   end
 
   def delete(%User{} = user) do
+    purge(user)
     BackgroundWorker.enqueue("delete_user", %{"user_id" => user.id})
   end
 
-  defp delete_and_invalidate_cache(%User{} = user) do
+  defp delete_from_db(%User{} = user) do
     invalidate_cache(user)
     Repo.delete(user)
   end
 
-  defp delete_or_purge(%User{local: false} = user), do: purge(user)
-
-  defp delete_or_purge(%User{local: true} = user) do
+  defp maybe_delete_from_db(%User{local: true} = user) do
     status = account_status(user)
 
-    case status do
-      :confirmation_pending ->
-        delete_and_invalidate_cache(user)
-
-      :approval_pending ->
-        delete_and_invalidate_cache(user)
-
-      _ ->
-        purge(user)
+    if status in [:confirmation_pending, :approval_pending] do
+      delete_from_db(user)
+    else
+      {:ok, user}
     end
   end
 
+  defp maybe_delete_from_db(user), do: {:ok, user}
+
   def perform(:force_password_reset, user), do: force_password_reset(user)
 
   @spec perform(atom(), User.t()) :: {:ok, User.t()}
@@ -1770,10 +1766,9 @@ defmodule Pleroma.User do
 
     delete_user_activities(user)
     delete_notifications_from_user_activities(user)
-
     delete_outgoing_pending_follow_requests(user)
 
-    delete_or_purge(user)
+    maybe_delete_from_db(user)
   end
 
   def perform(:set_activation_async, user, status), do: set_activation(user, status)