Merge branch 'fix-ics-feed-events-sorting' into 'main'
Fix ICS feed missing events: order by "begins_on" DESC See merge request framasoft/mobilizon!1512
This commit is contained in:
commit
b09f9053b2
|
@ -135,7 +135,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
|
|
||||||
%Page{total: total_events, elements: events} =
|
%Page{total: total_events, elements: events} =
|
||||||
if actor_id == relay_actor_id do
|
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
|
else
|
||||||
Events.list_public_events_for_actor(actor, page, limit)
|
Events.list_public_events_for_actor(actor, page, limit)
|
||||||
end
|
end
|
||||||
|
|
|
@ -387,13 +387,15 @@ defmodule Mobilizon.Events do
|
||||||
|> Repo.stream()
|
|> Repo.stream()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec list_public_local_events(integer | nil, integer | nil) :: Page.t(Event.t())
|
@spec list_public_local_events(integer | nil, integer | nil, atom | nil, atom | nil) ::
|
||||||
def list_public_local_events(page \\ nil, limit \\ nil) do
|
Page.t(Event.t())
|
||||||
|
def list_public_local_events(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do
|
||||||
Event
|
Event
|
||||||
|> filter_public_visibility()
|
|> filter_public_visibility()
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> filter_local()
|
|> filter_local()
|
||||||
|> preload_for_event()
|
|> preload_for_event()
|
||||||
|
|> event_order_by(sort, direction)
|
||||||
|> Page.build_page(page, limit)
|
|> Page.build_page(page, limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,13 @@ defmodule Mobilizon.Posts do
|
||||||
:private
|
:private
|
||||||
])
|
])
|
||||||
|
|
||||||
@spec list_public_local_posts(integer | nil, integer | nil) :: Page.t(Post.t())
|
@spec list_public_local_posts(integer | nil, integer | nil, atom | nil, atom | nil) ::
|
||||||
def list_public_local_posts(page \\ nil, limit \\ nil) do
|
Page.t(Post.t())
|
||||||
|
def list_public_local_posts(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do
|
||||||
Post
|
Post
|
||||||
|> filter_public()
|
|> filter_public()
|
||||||
|> filter_local()
|
|> filter_local()
|
||||||
|
|> order_posts(sort, direction)
|
||||||
|> preload_post_associations()
|
|> preload_post_associations()
|
||||||
|> Page.build_page(page, limit)
|
|> Page.build_page(page, limit)
|
||||||
end
|
end
|
||||||
|
@ -171,4 +173,13 @@ defmodule Mobilizon.Posts do
|
||||||
defp preload_post_associations(query, associations \\ @post_preloads) do
|
defp preload_post_associations(query, associations \\ @post_preloads) do
|
||||||
preload(query, ^associations)
|
preload(query, ^associations)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -96,8 +96,8 @@ defmodule Mobilizon.Service.Export.Common do
|
||||||
|
|
||||||
@spec fetch_instance_public_content(integer()) :: {:ok, list(Event.t()), list(Post.t())}
|
@spec fetch_instance_public_content(integer()) :: {:ok, list(Event.t()), list(Post.t())}
|
||||||
def fetch_instance_public_content(limit) do
|
def fetch_instance_public_content(limit) do
|
||||||
%Page{elements: events} = Events.list_public_local_events(1, limit)
|
%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}
|
{:ok, events, posts}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||||
|
|
||||||
@behaviour Cachable
|
@behaviour Cachable
|
||||||
|
|
||||||
@item_limit 500
|
@item_limit 5000
|
||||||
|
|
||||||
@spec version :: String.t()
|
@spec version :: String.t()
|
||||||
defp version, do: Config.instance_version()
|
defp version, do: Config.instance_version()
|
||||||
|
|
Loading…
Reference in a new issue