From 83f27282ba5c40c69cf7945e724685166bb3e5d4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 4 Jan 2021 10:13:17 -0600 Subject: [PATCH 1/3] Do not try to guess which pagination we need by the existence of an :offset param. Require explicit request to get offset pagination. --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +----- .../web/admin_api/controllers/admin_api_controller.ex | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 15f298bb8..9db72d6b2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -603,11 +603,7 @@ def fetch_user_activities(user, reading_user, params \\ %{}) do |> Map.put(:muting_user, reading_user) end - pagination_type = - cond do - !Map.has_key?(params, :offset) -> :keyset - true -> :offset - end + pagination_type = Map.get(params, :pagination_type) || :keyset %{ godmode: params[:godmode], diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index 6ef8d6061..1c7c26d98 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -110,7 +110,8 @@ def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickna limit: page_size, offset: (page - 1) * page_size, godmode: godmode, - exclude_reblogs: not with_reblogs + exclude_reblogs: not with_reblogs, + pagination_type: :offset }) conn From 0e93775ed0a35e348a0d13003680a478612fd6e3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 4 Jan 2021 11:04:58 -0600 Subject: [PATCH 2/3] Add test to validate profile pagination works with keyset --- .../controllers/account_controller_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index f6285853a..ba2f196f2 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -469,6 +469,19 @@ test "muted reactions", %{user: user, conn: conn} do } ] = result end + + test "paginates a user's statuses", %{user: user, conn: conn} do + {:ok, post1} = CommonAPI.post(user, %{status: "first post"}) + {:ok, _} = CommonAPI.post(user, %{status: "second post"}) + + response1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") + assert json_response(response1, 200) |> length() == 1 + + response2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&min_id=#{post1.id}") + assert json_response(response2, 200) |> length() == 1 + + refute response1 == response2 + end end defp local_and_remote_activities(%{local: local, remote: remote}) do From 95a0ae8a35f97eb27423ca0e7da722e8f7f135e5 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 5 Jan 2021 11:48:40 +0100 Subject: [PATCH 3/3] AccountControllerTest: Fix test logic --- .../controllers/account_controller_test.exs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index ba2f196f2..cc7b3cf8b 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -471,16 +471,18 @@ test "muted reactions", %{user: user, conn: conn} do end test "paginates a user's statuses", %{user: user, conn: conn} do - {:ok, post1} = CommonAPI.post(user, %{status: "first post"}) - {:ok, _} = CommonAPI.post(user, %{status: "second post"}) + {:ok, post_1} = CommonAPI.post(user, %{status: "first post"}) + {:ok, post_2} = CommonAPI.post(user, %{status: "second post"}) - response1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") - assert json_response(response1, 200) |> length() == 1 + response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") + assert [res] = json_response(response_1, 200) + assert res["id"] == post_2.id - response2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&min_id=#{post1.id}") - assert json_response(response2, 200) |> length() == 1 + response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}") + assert [res] = json_response(response_2, 200) + assert res["id"] == post_1.id - refute response1 == response2 + refute response_1 == response_2 end end