diff options
author | Maxim Filippov <colixer@gmail.com> | 2019-09-02 22:48:52 +0300 |
---|---|---|
committer | Maxim Filippov <colixer@gmail.com> | 2019-09-02 22:48:52 +0300 |
commit | a4c5f71e933c905433b80c90bcd626e7da703669 (patch) | |
tree | d75a728d2d449f8f5c999dc8f91172a2cf7c23f4 /lib/pleroma/pagination.ex | |
parent | 6d33c89c4d27a1b52e69e1c14b408726410a6326 (diff) | |
download | pleroma-a4c5f71e933c905433b80c90bcd626e7da703669.tar.gz |
Return total from pagination + tests
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) |