using exists instead of join with distinct
This commit is contained in:
parent
b1f9fa5245
commit
48fb2d0d0b
@ -109,14 +109,21 @@ defmodule Pleroma.User.Query do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:tags, tags}, query) when is_list(tags) and length(tags) > 0 do
|
defp compose_query({:tags, tags}, query) when is_list(tags) and length(tags) > 0 do
|
||||||
users_with_tags_query =
|
from(u in query,
|
||||||
from(u in User,
|
where:
|
||||||
join: t in assoc(u, :tags),
|
fragment(
|
||||||
where: t.name in ^tags,
|
"""
|
||||||
distinct: u
|
EXISTS (
|
||||||
|
SELECT 1 FROM tags t
|
||||||
|
JOIN users_tags ut ON ut.tag_id = t.id AND ut.user_id = ?
|
||||||
|
WHERE t.name = ANY(?)
|
||||||
|
LIMIT 1
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
u.id,
|
||||||
|
^tags
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
from(u in query, join: ut in subquery(users_with_tags_query), on: ut.id == u.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:is_admin, bool}, query) do
|
defp compose_query({:is_admin, bool}, query) do
|
||||||
|
Loading…
Reference in New Issue
Block a user