X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fpagination.ex;h=33e45a0eb45b8b83a3a00fae90f22dd562c94ed1;hb=77ed5fc67453f1030de39ce224b48f1846399397;hp=1b99e44f9304210b811ecd9668097847be2c395e;hpb=be48c1bafb0765675012c71d79a41ac490a964b7;p=akkoma
diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex
index 1b99e44f9..33e45a0eb 100644
--- a/lib/pleroma/pagination.ex
+++ b/lib/pleroma/pagination.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Pagination do
@@ -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)
@@ -87,6 +93,7 @@ defmodule Pleroma.Pagination do
max_id: :string,
offset: :integer,
limit: :integer,
+ skip_extra_order: :boolean,
skip_order: :boolean
}
@@ -108,6 +115,8 @@ defmodule Pleroma.Pagination do
defp restrict(query, :order, %{skip_order: true}, _), do: query
+ defp restrict(%{order_bys: [_ | _]} = query, :order, %{skip_extra_order: true}, _), do: query
+
defp restrict(query, :order, %{min_id: _}, table_binding) do
order_by(
query,