From ed2f8e45e9118177727b22f103f3c20476a891cf Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 31 Jan 2024 11:12:41 -0500 Subject: [PATCH] Pleroma.Web.MastodonAPI.SearchController: fix dialyzer errors Add a separate Pagination.paginate_list/2 function instead of overloading paginate/4 and complicating its matching and @spec --- lib/pleroma/pagination.ex | 9 +++++---- .../web/mastodon_api/controllers/search_controller.ex | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex index f12ca2819..8db732cc9 100644 --- a/lib/pleroma/pagination.ex +++ b/lib/pleroma/pagination.ex @@ -61,15 +61,16 @@ def fetch_paginated(query, params, :offset, table_binding) do |> 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(list, options, _method, _table_binding) when is_list(list) do + @spec paginate_list(list(), keyword()) :: list() + def paginate_list(list, options) do offset = options[:offset] || 0 limit = options[:limit] || 0 Enum.slice(list, offset, limit) 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 query |> restrict(:min_id, options, table_binding) diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex index 7fdf684d2..628aa311b 100644 --- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex @@ -156,7 +156,7 @@ defp prepare_tags(query, options) do tags end - Pleroma.Pagination.paginate(tags, options) + Pleroma.Pagination.paginate_list(tags, options) end defp add_joined_tag(tags) do