Merge branch 'formatting-fixes' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / utils.ex
index ef58b88d203ca483995cba0e072ef6369b078583..4e3a7e2bd6b0ffbadfda825aedefc1711cbfcc67 100644 (file)
@@ -90,7 +90,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   """
   def get_existing_like(actor, %{data: %{"id" => id}} = object) do
     query = from activity in Activity,
-      where: fragment("? @> ?", activity.data, ^%{actor: actor, object: id, type: "Like"})
+      where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
+      # this is to use the index
+      where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^id),
+      where: fragment("(?)->>'type' = 'Like'", activity.data)
+
     Repo.one(query)
   end
 
@@ -152,7 +156,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     query = from activity in Activity,
       where: fragment("? @> ?", activity.data, ^%{type: "Follow", actor: follower_id,
                                                   object: followed_id}),
-      order_by: [desc: :inserted_at],
+      order_by: [desc: :id],
       limit: 1
     Repo.one(query)
   end