diff --git a/config/config.exs b/config/config.exs index 44d0666c..f15398df 100644 --- a/config/config.exs +++ b/config/config.exs @@ -212,7 +212,8 @@ config :mobilizon, :activitypub, # One day actor_stale_period: 3_600 * 48, actor_key_rotation_delay: 3_600 * 48, - sign_object_fetches: true + sign_object_fetches: true, + stale_actor_search_exclusion_after: 3_600 * 24 * 7 config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Nominatim diff --git a/lib/graphql/api/search.ex b/lib/graphql/api/search.ex index 799f1234..3b002b6f 100644 --- a/lib/graphql/api/search.ex +++ b/lib/graphql/api/search.ex @@ -49,7 +49,8 @@ defmodule Mobilizon.GraphQL.API.Search do location: Map.get(args, :location), minimum_visibility: Map.get(args, :minimum_visibility, :public), current_actor_id: Map.get(args, :current_actor_id), - exclude_my_groups: Map.get(args, :exclude_my_groups, false) + exclude_my_groups: Map.get(args, :exclude_my_groups, false), + exclude_stale_actors: true ], page, limit diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 9058ec48..cbf854ff 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -461,6 +461,7 @@ defmodule Mobilizon.Actors do ) do term |> build_actors_by_username_or_name_page_query(options) + |> maybe_exclude_stale_actors(Keyword.get(options, :exclude_stale_actors, false)) |> maybe_exclude_my_groups( Keyword.get(options, :exclude_my_groups, false), Keyword.get(options, :current_actor_id) @@ -477,6 +478,17 @@ defmodule Mobilizon.Actors do defp maybe_exclude_my_groups(query, _, _), do: query + @spec maybe_exclude_stale_actors(Ecto.Queryable.t(), boolean()) :: Ecto.Query.t() + defp maybe_exclude_stale_actors(query, true) do + actor_stale_period = + Application.get_env(:mobilizon, :activitypub)[:stale_actor_search_exclusion_after] + + stale_date = DateTime.utc_now() |> DateTime.add(-actor_stale_period) + where(query, [a], is_nil(a.domain) or a.last_refreshed_at >= ^stale_date) + end + + defp maybe_exclude_stale_actors(query, false), do: query + @spec build_actors_by_username_or_name_page_query( String.t(), Keyword.t() diff --git a/test/graphql/api/search_test.exs b/test/graphql/api/search_test.exs index 62016294..7ef11646 100644 --- a/test/graphql/api/search_test.exs +++ b/test/graphql/api/search_test.exs @@ -53,7 +53,8 @@ defmodule Mobilizon.GraphQL.API.SearchTest do location: nil, minimum_visibility: :public, current_actor_id: nil, - exclude_my_groups: false + exclude_my_groups: false, + exclude_stale_actors: true ], 1, 10