Add FASP account search support (#34033)
This commit is contained in:
parent
6d017dbf10
commit
ac4b735c67
8 changed files with 130 additions and 3 deletions
30
app/workers/fasp/account_search_worker.rb
Normal file
30
app/workers/fasp/account_search_worker.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# 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?
|
||||
|
||||
async_refresh = AsyncRefresh.new("fasp:account_search:#{Digest::MD5.base64digest(query)}")
|
||||
|
||||
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?
|
||||
|
||||
account = fetch_service.call(uri)
|
||||
async_refresh.increment_result_count(by: 1) if account.present?
|
||||
end
|
||||
end
|
||||
ensure
|
||||
async_refresh&.finish!
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue