Refactor a little bit

This commit is contained in:
Maxim Filippov 2019-03-01 21:17:20 +03:00
parent a25c1313ae
commit f635b675b2
2 changed files with 8 additions and 16 deletions

View file

@ -763,17 +763,13 @@ defmodule Pleroma.User do
if options[:resolve], do: get_or_fetch(term) if options[:resolve], do: get_or_fetch(term)
fts_results = fts_results =
do_search(fts_search_subquery(term, query), options[:for_user], %{ do_search(fts_search_subquery(term, query), options[:for_user], limit: options[:limit])
limit: options[:limit]
})
{:ok, trigram_results} = {:ok, trigram_results} =
Repo.transaction(fn -> Repo.transaction(fn ->
Ecto.Adapters.SQL.query(Repo, "select set_limit(0.25)", []) Ecto.Adapters.SQL.query(Repo, "select set_limit(0.25)", [])
do_search(trigram_search_subquery(term, query), options[:for_user], %{ do_search(trigram_search_subquery(term, query), options[:for_user], limit: options[:limit])
limit: options[:limit]
})
end) end)
Enum.uniq_by(fts_results ++ trigram_results, & &1.id) Enum.uniq_by(fts_results ++ trigram_results, & &1.id)
@ -1024,12 +1020,8 @@ defmodule Pleroma.User do
update_and_set_cache(cng) update_and_set_cache(cng)
end end
def maybe_local_user_query(local) when local == true do def maybe_local_user_query(local) do
local_user_query() if local, do: local_user_query(), else: User
end
def maybe_local_user_query(local) when local == false do
User
end end
def local_user_query do def local_user_query do

View file

@ -70,11 +70,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
do: do:
conn conn
|> json( |> json(
AccountView.render("index.json", %{ AccountView.render("index.json",
users: users, users: users,
count: count, count: count,
page_size: @users_page_size page_size: @users_page_size
}) )
) )
end end
@ -89,11 +89,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
conn conn
|> json( |> json(
AccountView.render("index.json", %{ AccountView.render("index.json",
users: users, users: users,
count: length(users), count: length(users),
page_size: @users_page_size page_size: @users_page_size
}) )
) )
end end