Add max_id fetching to activity fetching.

This commit is contained in:
Roger Braun 2017-04-12 17:11:01 +02:00
parent 6a179a44be
commit b666f11d2f
2 changed files with 20 additions and 0 deletions

View File

@ -54,6 +54,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
query = from activity in query, query = from activity in query,
where: activity.id > ^since_id 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) Repo.all(query)
|> Enum.reverse |> Enum.reverse
end end

View File

@ -94,6 +94,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert length(activities) == 10 assert length(activities) == 10
assert last == last_expected assert last == last_expected
end 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 end
describe "uploading files" do describe "uploading files" do