akkoma/priv/repo/migrations/20250318000000_receiver_worker_id_key.exs
Oneric 195042bdc9 receiver_worker: prevent duplicate jobs
E.g. \*oma federates (most) follower-only posts multiple times
to each personal inbox. This commonly leads to race conditions
with jobs of several copies running at the same time and getting
past the initial "already known" check but then later all but
one will crash with an exception from the unique db index.

Since the only special thing we do with copies anyway is to discard them,
just don't create such duplicate jobs in the first place.
For the same reason and since failed jobs don't count towards
duplicates, this should have virtually no effect on federation.
2025-03-18 03:46:33 +01:00

22 lines
515 B
Elixir

defmodule Pleroma.Repo.Migrations.ReceiverWorkerIdKey do
use Ecto.Migration
def up() do
# since we currently still support PostgreSQL 12 and 13, do NOT use the args['id'] snytax!
"""
UPDATE public.oban_jobs
SET args = jsonb_set(
args,
'{id}',
to_jsonb(COALESCE(args#>>'{params,id}', id::text))
)
WHERE worker = 'Pleroma.Workers.ReceiverWorker';
"""
|> Pleroma.Repo.query!([], timeout: :infinity)
end
def down() do
# no action needed
:ok
end
end