From c83ff20d12dd8c871997d60835a2afba6c744a21 Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Thu, 27 Feb 2025 17:12:30 +0100 Subject: [PATCH] Send searches to FASP... ...to backfill accounts that might be missing. Sadly, this has no effect on the search performed, but has the potential to improvde future searches. --- app/services/account_search_service.rb | 6 ++++++ app/workers/fasp/account_search_worker.rb | 25 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 app/workers/fasp/account_search_worker.rb diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb index dab5f748bf..24adeb21b3 100644 --- a/app/services/account_search_service.rb +++ b/app/services/account_search_service.rb @@ -152,6 +152,12 @@ class AccountSearchService < BaseService 'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database' ) + # Trigger searching accounts using providers. + # This will not return any immediate results but has the + # potential to fill the local database with relevant + # accounts for the next time the search is performed. + Fasp::AccountSearchWorker.perform_async(@query) + search_service_results.compact.uniq.tap do |results| span.set_attribute('search.results.count', results.size) end diff --git a/app/workers/fasp/account_search_worker.rb b/app/workers/fasp/account_search_worker.rb new file mode 100644 index 0000000000..c5fddad857 --- /dev/null +++ b/app/workers/fasp/account_search_worker.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class Fasp::AccountSearchWorker + include Sidekiq::Worker + + sidekiq_options queue: 'fasp', retry: 0 + + def perform(query) + return unless Mastodon::Feature.fasp_enabled? + + account_search_providers = Fasp::Provider.with_capability('account_search') + return if account_search_providers.none? + + params = { term: query, limit: 10 }.to_query + fetch_service = ActivityPub::FetchRemoteActorService.new + + account_search_providers.each do |provider| + Fasp::Request.new(provider).get("/account_search/v0/search?#{params}").each do |uri| + next if Account.where(uri:).any? + + fetch_service.call(uri) + end + end + end +end