From b666f11d2fc32b10dce0d36e72cc285377c28f18 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 17:11:01 +0200 Subject: [PATCH] Add max_id fetching to activity fetching. --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 ++++++ test/web/activity_pub/activity_pub_test.exs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ec9c5e970..75e4101f2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -54,6 +54,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do query = from activity in query, where: activity.id > ^since_id + query = if opts["max_id"] do + from activity in query, where: activity.id < ^opts["max_id"] + else + query + end + Repo.all(query) |> Enum.reverse end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 2c6f67621..5cfd46238 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -94,6 +94,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert length(activities) == 10 assert last == last_expected end + + test "retrieves ids up to max_id" do + _first_activities = ActivityBuilder.insert_list(10) + activities = ActivityBuilder.insert_list(20) + later_activities = ActivityBuilder.insert_list(10) + max_id = List.first(later_activities).id + last_expected = List.last(activities) + + activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id}) + last = List.last(activities) + + assert length(activities) == 20 + assert last == last_expected + end end describe "uploading files" do