Merge remote-tracking branch 'origin/main'

This commit is contained in:
778a69cd 2023-12-20 14:19:10 +01:00
commit 05381e47e8
5 changed files with 18 additions and 6 deletions

View file

@ -135,7 +135,7 @@ defmodule Mobilizon.Federation.ActivityPub do
%Page{total: total_events, elements: events} =
if actor_id == relay_actor_id do
Events.list_public_local_events(page, limit)
Events.list_public_local_events(page, limit, :publish_at, :desc)
else
Events.list_public_events_for_actor(actor, page, limit)
end

View file

@ -387,7 +387,8 @@ defmodule Mobilizon.Events do
|> Repo.stream()
end
@spec list_public_local_events(integer | nil, integer | nil, atom | nil, atom | nil) :: Page.t(Event.t())
@spec list_public_local_events(integer | nil, integer | nil, atom | nil, atom | nil) ::
Page.t(Event.t())
def list_public_local_events(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do
Event
|> filter_public_visibility()

View file

@ -22,11 +22,13 @@ defmodule Mobilizon.Posts do
:private
])
@spec list_public_local_posts(integer | nil, integer | nil) :: Page.t(Post.t())
def list_public_local_posts(page \\ nil, limit \\ nil) do
@spec list_public_local_posts(integer | nil, integer | nil, atom | nil, atom | nil) ::
Page.t(Post.t())
def list_public_local_posts(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do
Post
|> filter_public()
|> filter_local()
|> order_posts(sort, direction)
|> preload_post_associations()
|> Page.build_page(page, limit)
end
@ -171,4 +173,13 @@ defmodule Mobilizon.Posts do
defp preload_post_associations(query, associations \\ @post_preloads) do
preload(query, ^associations)
end
@spec order_posts(Ecto.Queryable.t(), atom | nil, atom | nil) :: Ecto.Queryable.t()
def order_posts(query, nil, _direction), do: query
def order_posts(query, _sort, nil), do: query
def order_posts(query, sort, direction) do
order_by_param = Keyword.new([{direction, sort}])
order_by(query, ^order_by_param)
end
end

View file

@ -97,7 +97,7 @@ defmodule Mobilizon.Service.Export.Common do
@spec fetch_instance_public_content(integer()) :: {:ok, list(Event.t()), list(Post.t())}
def fetch_instance_public_content(limit) do
%Page{elements: events} = Events.list_public_local_events(1, limit, :begins_on, :desc)
%Page{elements: posts} = Posts.list_public_local_posts(1, limit)
%Page{elements: posts} = Posts.list_public_local_posts(1, limit, :publish_at, :desc)
{:ok, events, posts}
end

View file

@ -21,7 +21,7 @@ defmodule Mobilizon.Service.Export.Feed do
@behaviour Cachable
@item_limit 500
@item_limit 5000
@spec version :: String.t()
defp version, do: Config.instance_version()