Use inner lateral join to not get dropped in :total

This commit is contained in:
FloatingGhost 2022-10-10 16:45:02 +01:00
parent 574f010bc8
commit ca9e6ffc55
2 changed files with 1 additions and 2 deletions

View file

@ -369,7 +369,7 @@ def following_requests_for_actor(%User{ap_id: ap_id}) do
def restrict_deactivated_users(query) do def restrict_deactivated_users(query) do
query query
|> join(:inner, [activity], user in User, as: :user, on: activity.actor == user.ap_id and user.is_active == true) |> join(:inner_lateral, [activity], active in fragment("SELECT is_active from users WHERE ap_id = ? AND is_active = TRUE", activity.actor))
end end
defdelegate search(user, query, options \\ []), to: Pleroma.Search.DatabaseSearch defdelegate search(user, query, options \\ []), to: Pleroma.Search.DatabaseSearch

View file

@ -507,7 +507,6 @@ def fetch_latest_direct_activity_id_for_context(context, opts \\ %{}) do
defp fetch_paginated_optimized(query, opts, pagination) do defp fetch_paginated_optimized(query, opts, pagination) do
# Note: tag-filtering funcs may apply "ORDER BY objects.id DESC", # Note: tag-filtering funcs may apply "ORDER BY objects.id DESC",
# and extra sorting on "activities.id DESC NULLS LAST" would worse the query plan # and extra sorting on "activities.id DESC NULLS LAST" would worse the query plan
IO.inspect(Repo.to_sql(:all, query))
opts = Map.put(opts, :skip_extra_order, true) opts = Map.put(opts, :skip_extra_order, true)
Pagination.fetch_paginated(query, opts, pagination) Pagination.fetch_paginated(query, opts, pagination)