mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Use more efficient query to fetch likes.
This commit is contained in:
parent
9af560083f
commit
5293516730
1 changed files with 5 additions and 1 deletions
|
@ -90,7 +90,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
"""
|
"""
|
||||||
def get_existing_like(actor, %{data: %{"id" => id}} = object) do
|
def get_existing_like(actor, %{data: %{"id" => id}} = object) do
|
||||||
query = from activity in Activity,
|
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)
|
Repo.one(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue