projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use the import
[akkoma]
/
lib
/
pleroma
/
pagination.ex
diff --git
a/lib/pleroma/pagination.ex
b/lib/pleroma/pagination.ex
index 0ccc7b1f2ad258dd0a53f97cbdda50810d9849c7..9a3795769e450e79a52d084b338d9763ec4908e7 100644
(file)
--- a/
lib/pleroma/pagination.ex
+++ b/
lib/pleroma/pagination.ex
@@
-16,6
+16,9
@@
defmodule Pleroma.Pagination do
@default_limit 20
@max_limit 40
@default_limit 20
@max_limit 40
+ @page_keys ["max_id", "min_id", "limit", "since_id", "order"]
+
+ def page_keys, do: @page_keys
@spec fetch_paginated(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def fetch_paginated(query, params, type \\ :keyset, table_binding \\ nil)
@spec fetch_paginated(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def fetch_paginated(query, params, type \\ :keyset, table_binding \\ nil)
@@
-61,6
+64,12
@@
defmodule Pleroma.Pagination do
@spec paginate(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def paginate(query, options, method \\ :keyset, table_binding \\ nil)
@spec paginate(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def paginate(query, options, method \\ :keyset, table_binding \\ nil)
+ def paginate(list, options, _method, _table_binding) when is_list(list) do
+ offset = options[:offset] || 0
+ limit = options[:limit] || 0
+ Enum.slice(list, offset, limit)
+ end
+
def paginate(query, options, :keyset, table_binding) do
query
|> restrict(:min_id, options, table_binding)
def paginate(query, options, :keyset, table_binding) do
query
|> restrict(:min_id, options, table_binding)