projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Extract timeline actions from `MastodonAPIController` into `TimelineController`
[akkoma]
/
lib
/
pleroma
/
pagination.ex
diff --git
a/lib/pleroma/pagination.ex
b/lib/pleroma/pagination.ex
index 2b869ccdcc494c2a9bb158772da59c1167aa7529..9d279fba7939f12256d57cf41261f0e506fba562 100644
(file)
--- a/
lib/pleroma/pagination.ex
+++ b/
lib/pleroma/pagination.ex
@@
-16,6
+16,15
@@
defmodule Pleroma.Pagination do
def fetch_paginated(query, params, type \\ :keyset)
def fetch_paginated(query, params, type \\ :keyset)
+ def fetch_paginated(query, %{"total" => true} = params, :keyset) do
+ total = Repo.aggregate(query, :count, :id)
+
+ %{
+ total: total,
+ items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset)
+ }
+ end
+
def fetch_paginated(query, params, :keyset) do
options = cast_params(params)
def fetch_paginated(query, params, :keyset) do
options = cast_params(params)
@@
-25,6
+34,15
@@
defmodule Pleroma.Pagination do
|> enforce_order(options)
end
|> enforce_order(options)
end
+ def fetch_paginated(query, %{"total" => true} = params, :offset) do
+ total = Repo.aggregate(query, :count, :id)
+
+ %{
+ total: total,
+ items: fetch_paginated(query, Map.drop(params, ["total"]), :offset)
+ }
+ end
+
def fetch_paginated(query, params, :offset) do
options = cast_params(params)
def fetch_paginated(query, params, :offset) do
options = cast_params(params)
@@
-46,6
+64,7
@@
defmodule Pleroma.Pagination do
def paginate(query, options, :offset) do
query
def paginate(query, options, :offset) do
query
+ |> restrict(:order, options)
|> restrict(:offset, options)
|> restrict(:limit, options)
end
|> restrict(:offset, options)
|> restrict(:limit, options)
end