projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Apply suggestion to lib/pleroma/web/activity_pub/activity_pub_controller.ex
[akkoma]
/
lib
/
pleroma
/
pagination.ex
diff --git
a/lib/pleroma/pagination.ex
b/lib/pleroma/pagination.ex
index f435e5c9cb43c0d262ef231d3a9985d2eab75a9b..2b869ccdcc494c2a9bb158772da59c1167aa7529 100644
(file)
--- a/
lib/pleroma/pagination.ex
+++ b/
lib/pleroma/pagination.ex
@@
-1,3
+1,7
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Pagination do
@moduledoc """
Implements Mastodon-compatible pagination.
defmodule Pleroma.Pagination do
@moduledoc """
Implements Mastodon-compatible pagination.
@@
-10,16
+14,28
@@
defmodule Pleroma.Pagination do
@default_limit 20
@default_limit 20
- def fetch_paginated(query, params) do
+ def fetch_paginated(query, params, type \\ :keyset)
+
+ def fetch_paginated(query, params, :keyset) do
options = cast_params(params)
query
options = cast_params(params)
query
- |> paginate(options)
+ |> paginate(options
, :keyset
)
|> Repo.all()
|> enforce_order(options)
end
|> Repo.all()
|> enforce_order(options)
end
- def paginate(query, options) do
+ 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
query
|> restrict(:min_id, options)
|> restrict(:since_id, options)
query
|> restrict(:min_id, options)
|> restrict(:since_id, options)
@@
-28,11
+44,18
@@
defmodule Pleroma.Pagination do
|> restrict(:limit, options)
end
|> restrict(:limit, options)
end
+ def paginate(query, options, :offset) do
+ query
+ |> restrict(:offset, options)
+ |> restrict(:limit, options)
+ end
+
defp cast_params(params) do
param_types = %{
min_id: :string,
since_id: :string,
max_id: :string,
defp cast_params(params) do
param_types = %{
min_id: :string,
since_id: :string,
max_id: :string,
+ offset: :integer,
limit: :integer
}
limit: :integer
}
@@
-66,6
+89,10
@@
defmodule Pleroma.Pagination do
order_by(query, [u], fragment("? desc nulls last", u.id))
end
order_by(query, [u], fragment("? desc nulls last", u.id))
end
+ defp restrict(query, :offset, %{offset: offset}) do
+ offset(query, ^offset)
+ end
+
defp restrict(query, :limit, options) do
limit = Map.get(options, :limit, @default_limit)
defp restrict(query, :limit, options) do
limit = Map.get(options, :limit, @default_limit)