[#3213] Experimental / debug feature: database: [improved_hashtag_timeline: :preselect_hashtag_ids].

This commit is contained in:
Ivan Tashkinov 2021-02-18 21:03:06 +03:00
parent b981edad8a
commit 998437d4a4

View file

@ -787,19 +787,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end end
defp restrict_hashtag_any(query, %{tag: [_ | _] = tags}) do defp restrict_hashtag_any(query, %{tag: [_ | _] = tags}) do
from( # TODO: refactor: debug / experimental feature
[_activity, object] in query, if Config.get([:database, :improved_hashtag_timeline]) == :preselect_hashtag_ids do
where: hashtag_ids =
fragment( from(ht in Pleroma.Hashtag,
""" where: fragment("name = ANY(?::citext[])", ^tags),
EXISTS (SELECT 1 FROM hashtags JOIN hashtags_objects select: ht.id
ON hashtags_objects.hashtag_id = hashtags.id WHERE hashtags.name = ANY(?::citext[])
AND hashtags_objects.object_id = ? LIMIT 1)
""",
^tags,
object.id
) )
) |> Repo.all()
from(
[_activity, object] in query,
where:
fragment(
"""
EXISTS (
SELECT 1 FROM hashtags_objects WHERE hashtag_id = ANY(?) AND object_id = ? LIMIT 1)
""",
^hashtag_ids,
object.id
)
)
else
from(
[_activity, object] in query,
where:
fragment(
"""
EXISTS (SELECT 1 FROM hashtags JOIN hashtags_objects
ON hashtags_objects.hashtag_id = hashtags.id WHERE hashtags.name = ANY(?::citext[])
AND hashtags_objects.object_id = ? LIMIT 1)
""",
^tags,
object.id
)
)
end
end end
defp restrict_hashtag_any(query, %{tag: tag}) when is_binary(tag) do defp restrict_hashtag_any(query, %{tag: tag}) when is_binary(tag) do