diff options
Diffstat (limited to 'lib/pleroma/pagination.ex')
-rw-r--r-- | lib/pleroma/pagination.ex | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex index 2b869ccdc..d21ecf628 100644 --- a/lib/pleroma/pagination.ex +++ b/lib/pleroma/pagination.ex @@ -18,19 +18,29 @@ defmodule Pleroma.Pagination do def fetch_paginated(query, params, :keyset) do options = cast_params(params) - - query - |> paginate(options, :keyset) - |> Repo.all() - |> enforce_order(options) + total = Repo.aggregate(query, :count, :id) + + %{ + total: total, + items: + query + |> paginate(options, :keyset) + |> Repo.all() + |> enforce_order(options) + } end def fetch_paginated(query, params, :offset) do options = cast_params(params) - - query - |> paginate(options, :offset) - |> Repo.all() + total = Repo.aggregate(query, :count, :id) + + %{ + total: total, + items: + query + |> paginate(options, :offset) + |> Repo.all() + } end def paginate(query, options, method \\ :keyset) |