X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fpagination.ex;h=b55379c4a96c767978b57c894fd237030b693d6d;hb=4fabf83ad01352442906d79187aeab4c777f4df8;hp=2b869ccdcc494c2a9bb158772da59c1167aa7529;hpb=64a946643e6f9159a8029be8ec9e0b71b04906f3;p=akkoma diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex index 2b869ccdc..b55379c4a 100644 --- a/lib/pleroma/pagination.ex +++ b/lib/pleroma/pagination.ex @@ -16,6 +16,15 @@ defmodule Pleroma.Pagination do def fetch_paginated(query, params, type \\ :keyset) + def fetch_paginated(query, %{"total" => true} = params, :keyset) do + total = Repo.aggregate(query, :count, :id) + + %{ + total: total, + items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset) + } + end + def fetch_paginated(query, params, :keyset) do options = cast_params(params) @@ -25,6 +34,15 @@ defmodule Pleroma.Pagination do |> enforce_order(options) end + def fetch_paginated(query, %{"total" => true} = params, :offset) do + total = Repo.aggregate(query, :count, :id) + + %{ + total: total, + items: fetch_paginated(query, Map.drop(params, ["total"]), :offset) + } + end + def fetch_paginated(query, params, :offset) do options = cast_params(params)