From: Roger Braun Date: Tue, 24 Oct 2017 12:39:01 +0000 (+0200) Subject: Use more efficient query to fetch likes. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=529351673090d8165bb0c54f9e957e611fcacd72;p=akkoma Use more efficient query to fetch likes. --- diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 4b8e6b690..4e3a7e2bd 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -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