
There were two issues leading to needles effort: Most importnatly, the use of AP IDs as "source_url" meant multiple simultaneous jobs got scheduled for the same instance even with the default unique settings. Also jobs were scheduled uncontionally for each processed AP object meaning we incured oberhead from managing Oban jobs even if we knew it wasn't necessary. By comparison the single query to check if an update is needed should be cheaper overall.
39 lines
927 B
Elixir
39 lines
927 B
Elixir
defmodule Pleroma.Workers.NodeInfoFetcherWorker do
|
|
use Pleroma.Workers.WorkerHelper,
|
|
queue: "nodeinfo_fetcher",
|
|
unique: [
|
|
keys: [:op, :source_url],
|
|
# old jobs still get pruned after a short while
|
|
period: :infinity,
|
|
states: Oban.Job.states()
|
|
]
|
|
|
|
alias Oban.Job
|
|
alias Pleroma.Instances.Instance
|
|
|
|
def enqueue(op, %{"source_url" => ap_id} = params, worker_args) do
|
|
# reduce to base url to avoid enqueueing unneccessary duplicates
|
|
domain =
|
|
ap_id
|
|
|> URI.parse()
|
|
|> URI.merge("/")
|
|
|
|
if Instance.needs_update(domain) do
|
|
do_enqueue(op, %{params | "source_url" => URI.to_string(domain)}, worker_args)
|
|
else
|
|
:ok
|
|
end
|
|
end
|
|
|
|
@impl Oban.Worker
|
|
def perform(%Job{
|
|
args: %{"op" => "process", "source_url" => domain}
|
|
}) do
|
|
uri =
|
|
domain
|
|
|> URI.parse()
|
|
|> URI.merge("/")
|
|
|
|
Instance.update_metadata(uri)
|
|
end
|
|
end
|