projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'fix/trailing-format-plug-oauth' into 'develop'
[akkoma]
/
lib
/
pleroma
/
pagination.ex
diff --git
a/lib/pleroma/pagination.ex
b/lib/pleroma/pagination.ex
index d21ecf628400bb83913d6f1577655b0b775834ea..9d279fba7939f12256d57cf41261f0e506fba562 100644
(file)
--- 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, 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,
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
}
end
- def fetch_paginated(query, params, :
off
set) do
+ def fetch_paginated(query, params, :
key
set) do
options = cast_params(params)
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,
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
}
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
def paginate(query, options, method \\ :keyset)
def paginate(query, options, :keyset) do
@@
-56,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