Add limiting to activity pub fetching.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
1 defmodule Pleroma.Web.ActivityPub.ActivityPub do
2 alias Pleroma.Repo
3 alias Pleroma.Activity
4 import Ecto.Query
5
6 def insert(map) when is_map(map) do
7 Repo.insert(%Activity{data: map})
8 end
9
10 def fetch_public_activities do
11 query = from activity in Activity,
12 where: fragment(~s(? @> '{"to": ["https://www.w3.org/ns/activitystreams#Public"]}'), activity.data),
13 limit: 20,
14 order_by: [desc: :inserted_at]
15
16 Repo.all(query)
17 |> Enum.reverse
18 end
19 end