Allow to exclude stale actors from group search (one week without refreshment)

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-01 16:48:46 +02:00
parent 2e1c284565
commit d2864a22d9
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
4 changed files with 18 additions and 3 deletions

View file

@ -212,7 +212,8 @@ config :mobilizon, :activitypub,
# One day # One day
actor_stale_period: 3_600 * 48, actor_stale_period: 3_600 * 48,
actor_key_rotation_delay: 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 config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Nominatim

View file

@ -49,7 +49,8 @@ defmodule Mobilizon.GraphQL.API.Search do
location: Map.get(args, :location), location: Map.get(args, :location),
minimum_visibility: Map.get(args, :minimum_visibility, :public), minimum_visibility: Map.get(args, :minimum_visibility, :public),
current_actor_id: Map.get(args, :current_actor_id), 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, page,
limit limit

View file

@ -461,6 +461,7 @@ defmodule Mobilizon.Actors do
) do ) do
term term
|> build_actors_by_username_or_name_page_query(options) |> build_actors_by_username_or_name_page_query(options)
|> maybe_exclude_stale_actors(Keyword.get(options, :exclude_stale_actors, false))
|> maybe_exclude_my_groups( |> maybe_exclude_my_groups(
Keyword.get(options, :exclude_my_groups, false), Keyword.get(options, :exclude_my_groups, false),
Keyword.get(options, :current_actor_id) Keyword.get(options, :current_actor_id)
@ -477,6 +478,17 @@ defmodule Mobilizon.Actors do
defp maybe_exclude_my_groups(query, _, _), do: query 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( @spec build_actors_by_username_or_name_page_query(
String.t(), String.t(),
Keyword.t() Keyword.t()

View file

@ -53,7 +53,8 @@ defmodule Mobilizon.GraphQL.API.SearchTest do
location: nil, location: nil,
minimum_visibility: :public, minimum_visibility: :public,
current_actor_id: nil, current_actor_id: nil,
exclude_my_groups: false exclude_my_groups: false,
exclude_stale_actors: true
], ],
1, 1,
10 10