aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/pagination.ex
diff options
context:
space:
mode:
authorMaxim Filippov <colixer@gmail.com>2019-09-03 13:58:27 +0300
committerMaxim Filippov <colixer@gmail.com>2019-09-03 13:58:27 +0300
commitb15cfd80ef5d5bc971f78a53dfa3d37dec4499a5 (patch)
tree2d9a0190fdb62d88d5c5accedfcd65447be8fa0a /lib/pleroma/pagination.ex
parenta4c5f71e933c905433b80c90bcd626e7da703669 (diff)
downloadpleroma-b15cfd80ef5d5bc971f78a53dfa3d37dec4499a5.tar.gz
Return "total" optionally
Diffstat (limited to 'lib/pleroma/pagination.ex')
-rw-r--r--lib/pleroma/pagination.ex32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex
index d21ecf628..b55379c4a 100644
--- a/lib/pleroma/pagination.ex
+++ b/lib/pleroma/pagination.ex
@@ -16,33 +16,41 @@ defmodule Pleroma.Pagination do
def fetch_paginated(query, params, type \\ :keyset)
- def fetch_paginated(query, params, :keyset) do
- options = cast_params(params)
+ def fetch_paginated(query, %{"total" => true} = params, :keyset) do
total = Repo.aggregate(query, :count, :id)
%{
total: total,
- items:
- query
- |> paginate(options, :keyset)
- |> Repo.all()
- |> enforce_order(options)
+ items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset)
}
end
- def fetch_paginated(query, params, :offset) do
+ def fetch_paginated(query, params, :keyset) do
options = cast_params(params)
+
+ query
+ |> paginate(options, :keyset)
+ |> Repo.all()
+ |> enforce_order(options)
+ end
+
+ def fetch_paginated(query, %{"total" => true} = params, :offset) do
total = Repo.aggregate(query, :count, :id)
%{
total: total,
- items:
- query
- |> paginate(options, :offset)
- |> Repo.all()
+ items: fetch_paginated(query, Map.drop(params, ["total"]), :offset)
}
end
+ def fetch_paginated(query, params, :offset) do
+ options = cast_params(params)
+
+ query
+ |> paginate(options, :offset)
+ |> Repo.all()
+ end
+
def paginate(query, options, method \\ :keyset)
def paginate(query, options, :keyset) do