diff options
author | Roger Braun <rbraun@Bobble.local> | 2017-10-24 14:39:01 +0200 |
---|---|---|
committer | Roger Braun <rbraun@Bobble.local> | 2017-10-24 14:39:01 +0200 |
commit | 529351673090d8165bb0c54f9e957e611fcacd72 (patch) | |
tree | 63235eb9fb0b555cccefd4cd1cb0860d9c9409b1 /lib | |
parent | 9af560083fcc513a7b3c41b06f4ed307c50a7529 (diff) | |
download | pleroma-529351673090d8165bb0c54f9e957e611fcacd72.tar.gz |
Use more efficient query to fetch likes.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 6 |
1 files changed, 5 insertions, 1 deletions
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 |