aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2021-02-23 15:14:37 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2021-03-20 08:36:31 +0300
commit48fb2d0d0befa5a34e30624f04e23689c81c5276 (patch)
tree516e90b8c0c7752e45c408bc73e17676f9a81c98
parentb1f9fa5245cca4ed2d737150585f5732fca1ae8e (diff)
downloadpleroma-48fb2d0d0befa5a34e30624f04e23689c81c5276.tar.gz
using exists instead of join with distinct
-rw-r--r--lib/pleroma/user/query.ex23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex
index 2c29aef3d..f5f742bd1 100644
--- a/lib/pleroma/user/query.ex
+++ b/lib/pleroma/user/query.ex
@@ -109,14 +109,21 @@ defmodule Pleroma.User.Query do
end
defp compose_query({:tags, tags}, query) when is_list(tags) and length(tags) > 0 do
- users_with_tags_query =
- from(u in User,
- join: t in assoc(u, :tags),
- where: t.name in ^tags,
- distinct: u
- )
-
- from(u in query, join: ut in subquery(users_with_tags_query), on: ut.id == u.id)
+ from(u in query,
+ where:
+ fragment(
+ """
+ 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
+ )
+ )
end
defp compose_query({:is_admin, bool}, query) do