projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update docs
[akkoma]
/
lib
/
pleroma
/
pagination.ex
diff --git
a/lib/pleroma/pagination.ex
b/lib/pleroma/pagination.ex
index 43fb7babfadcc448f98761fd86659d0bc4634f05..1b99e44f9304210b811ecd9668097847be2c395e 100644
(file)
--- a/
lib/pleroma/pagination.ex
+++ b/
lib/pleroma/pagination.ex
@@
-1,5
+1,5
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-20
19
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-20
20
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Pagination do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Pagination do
@@
-12,20
+12,23
@@
defmodule Pleroma.Pagination do
alias Pleroma.Repo
alias Pleroma.Repo
+ @type type :: :keyset | :offset
+
@default_limit 20
@max_limit 40
@page_keys ["max_id", "min_id", "limit", "since_id", "order"]
def page_keys, do: @page_keys
@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)
def fetch_paginated(query, params, type \\ :keyset, table_binding \\ nil)
- def fetch_paginated(query, %{
"total" =>
true} = params, :keyset, table_binding) do
+ def fetch_paginated(query, %{
total:
true} = params, :keyset, table_binding) do
total = Repo.aggregate(query, :count, :id)
%{
total: total,
total = Repo.aggregate(query, :count, :id)
%{
total: total,
- items: fetch_paginated(query, Map.drop(params, [
"total"
]), :keyset, table_binding)
+ items: fetch_paginated(query, Map.drop(params, [
:total
]), :keyset, table_binding)
}
end
}
end
@@
-38,7
+41,7
@@
defmodule Pleroma.Pagination do
|> enforce_order(options)
end
|> enforce_order(options)
end
- def fetch_paginated(query, %{
"total" =>
true} = params, :offset, table_binding) do
+ def fetch_paginated(query, %{
total:
true} = params, :offset, table_binding) do
total =
query
|> Ecto.Query.exclude(:left_join)
total =
query
|> Ecto.Query.exclude(:left_join)
@@
-46,7
+49,7
@@
defmodule Pleroma.Pagination do
%{
total: total,
%{
total: total,
- items: fetch_paginated(query, Map.drop(params, [
"total"
]), :offset, table_binding)
+ items: fetch_paginated(query, Map.drop(params, [
:total
]), :offset, table_binding)
}
end
}
end
@@
-58,6
+61,7
@@
defmodule Pleroma.Pagination do
|> Repo.all()
end
|> Repo.all()
end
+ @spec paginate(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def paginate(query, options, method \\ :keyset, table_binding \\ nil)
def paginate(query, options, :keyset, table_binding) do
def paginate(query, options, method \\ :keyset, table_binding \\ nil)
def paginate(query, options, :keyset, table_binding) do
@@
-86,12
+90,6
@@
defmodule Pleroma.Pagination do
skip_order: :boolean
}
skip_order: :boolean
}
- params =
- Enum.reduce(params, %{}, fn
- {key, _value}, acc when is_atom(key) -> Map.drop(acc, [key])
- {key, value}, acc -> Map.put(acc, key, value)
- end)
-
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
changeset.changes
end
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
changeset.changes
end