From 31411bfc038ebc0562f117a6ee913e5a2853f8ed Mon Sep 17 00:00:00 2001 From: summersamara Date: Wed, 20 Dec 2023 02:09:46 +0100 Subject: [PATCH 1/4] Fix ICS feed missing events: order by "begins_on" DESC so that the latest events are always included https://git.potsda.mn/potsda.mn/mobilizon/issues/37 --- lib/mobilizon/events/events.ex | 6 ++++-- lib/service/export/common.ex | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 8796ae442..3fa4cbaf9 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -387,13 +387,15 @@ defmodule Mobilizon.Events do |> Repo.stream() end - @spec list_public_local_events(integer | nil, integer | nil) :: Page.t(Event.t()) - def list_public_local_events(page \\ nil, limit \\ nil) do + @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() |> filter_draft() |> filter_local() |> preload_for_event() + |> event_order_by(sort, direction) |> Page.build_page(page, limit) end diff --git a/lib/service/export/common.ex b/lib/service/export/common.ex index 14da864de..9f3175642 100644 --- a/lib/service/export/common.ex +++ b/lib/service/export/common.ex @@ -96,7 +96,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) + %Page{elements: events} = Events.list_public_local_events(1, limit, :begins_on, :desc) %Page{elements: posts} = Posts.list_public_local_posts(1, limit) {:ok, events, posts} end From e73fd9b370b9679a0ab424a0bd44f262a21a4697 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 20 Dec 2023 09:24:48 +0100 Subject: [PATCH 2/4] fix(activitypub): make relay outbox events ordered by desc publication date Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 12ab02376..6a23293db 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -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 From 3c7585614971849035011ede6c0d5d2d5621df81 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 20 Dec 2023 09:26:28 +0100 Subject: [PATCH 3/4] fix(feeds): make sure posts for feeds are ordered by publication date desc Signed-off-by: Thomas Citharel --- lib/mobilizon/posts/posts.ex | 15 +++++++++++++-- lib/service/export/common.ex | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/mobilizon/posts/posts.ex b/lib/mobilizon/posts/posts.ex index 5fe60b433..97387b709 100644 --- a/lib/mobilizon/posts/posts.ex +++ b/lib/mobilizon/posts/posts.ex @@ -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 diff --git a/lib/service/export/common.ex b/lib/service/export/common.ex index 9f3175642..149055e31 100644 --- a/lib/service/export/common.ex +++ b/lib/service/export/common.ex @@ -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 From ff0440c634ac17813607f5929cd4024d87601c3b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 20 Dec 2023 09:26:58 +0100 Subject: [PATCH 4/4] fix(feeds): increase feed item limit from 500 to 5000 Signed-off-by: Thomas Citharel --- lib/service/export/feed.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service/export/feed.ex b/lib/service/export/feed.ex index 80ec7dcb4..cc1a0294a 100644 --- a/lib/service/export/feed.ex +++ b/lib/service/export/feed.ex @@ -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()