From 1cd6194deeca32a96a31fc43c0ed27daadd65f64 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 24 May 2018 12:44:26 +0200 Subject: [PATCH] More efficient queries. --- lib/pleroma/web/activity_pub/utils.ex | 5 +++-- test/support/factory.ex | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 937f032c3..a3feca480 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -242,8 +242,9 @@ def fetch_latest_follow(%User{ap_id: follower_id}, %User{ap_id: followed_id}) do fragment( "? @> ?", activity.data, - ^%{type: "Follow", actor: follower_id, object: followed_id} + ^%{type: "Follow", object: followed_id} ), + where: activity.actor == ^follower_id, order_by: [desc: :id], limit: 1 ) @@ -260,7 +261,7 @@ def get_existing_announce(actor, %{data: %{"id" => id}}) do query = from( activity in Activity, - where: fragment("(?)->>'actor' = ?", activity.data, ^actor), + where: activity.actor == ^actor, # this is to use the index where: fragment( diff --git a/test/support/factory.ex b/test/support/factory.ex index 8e21e2562..b2e98c8d1 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -95,7 +95,8 @@ def follow_activity_factory do } %Pleroma.Activity{ - data: data + data: data, + actor: follower.ap_id } end