diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-06-25 14:16:28 -0500 |
---|---|---|
committer | Mark Felder <feld@FreeBSD.org> | 2020-06-25 14:26:21 -0500 |
commit | 433c01b370f4bf68d3f016d86c1527b1319e7a0c (patch) | |
tree | 607d6c7e4e578d6e0ff95963b5565baefc207d85 /lib/pleroma/pagination.ex | |
parent | d4b20c96c4030ebb5eb908dc6efcf45be7a8355d (diff) | |
parent | 1d0804b49f56fe722b12f83269d98acfdee7ac77 (diff) | |
download | pleroma-433c01b370f4bf68d3f016d86c1527b1319e7a0c.tar.gz |
Merge branch 'develop' into refactor/notification_settings
Diffstat (limited to 'lib/pleroma/pagination.ex')
-rw-r--r-- | lib/pleroma/pagination.ex | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex index d43a96cd2..9a3795769 100644 --- a/lib/pleroma/pagination.ex +++ b/lib/pleroma/pagination.ex @@ -23,12 +23,12 @@ defmodule Pleroma.Pagination do @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, %{"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, - items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset, table_binding) + items: fetch_paginated(query, Map.drop(params, [:total]), :keyset, table_binding) } end @@ -41,7 +41,7 @@ defmodule Pleroma.Pagination do |> 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) @@ -49,7 +49,7 @@ defmodule Pleroma.Pagination do %{ 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 @@ -64,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) + 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) @@ -90,12 +96,6 @@ defmodule Pleroma.Pagination do 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 |