Merge remote-tracking branch 'origin/develop' into fix-slow-relationships
[akkoma] / lib / pleroma / web / activity_pub / utils.ex
index 86b6e702984a31a6101a3eeefe97b52aa506857b..0c614a8830f6d6b6db2733e17dc8f353b1939b31 100644 (file)
@@ -230,21 +230,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     end)
   end
 
-  # Only federate user icon if not nil
-  # Prevents federating instance default avatars
-  def maybe_make_icon(user) do
-    if User.avatar_url_ap(user) do
-      %{
-        "icon" => %{
-          "type" => "Image",
-          "url" => User.avatar_url_ap(user)
-        }
-      }
-    else
-      %{}
-    end
-  end
-
   #### Like-related helpers
 
   @doc """
@@ -369,7 +354,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
         [state, actor, object]
       )
 
-      activity = Repo.get(Activity, activity.id)
+      activity = Activity.get_by_id(activity.id)
       {:ok, activity}
     rescue
       e ->
@@ -419,13 +404,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
             activity.data
           ),
         where: activity.actor == ^follower_id,
+        # this is to use the index
         where:
           fragment(
-            "? @> ?",
+            "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
+            activity.data,
             activity.data,
-            ^%{object: followed_id}
+            ^followed_id
           ),
-        order_by: [desc: :id],
+        order_by: [fragment("? desc nulls last", activity.id)],
         limit: 1
       )
 
@@ -582,13 +569,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
             activity.data
           ),
         where: activity.actor == ^blocker_id,
+        # this is to use the index
         where:
           fragment(
-            "? @> ?",
+            "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
+            activity.data,
             activity.data,
-            ^%{object: blocked_id}
+            ^blocked_id
           ),
-        order_by: [desc: :id],
+        order_by: [fragment("? desc nulls last", activity.id)],
         limit: 1
       )