Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
852B

  1. defmodule Pleroma.Repo.Migrations.RemoveDuplicatesFromActivityExpirationQueue do
  2. use Ecto.Migration
  3. import Ecto.Query, only: [from: 2]
  4. def up do
  5. duplicate_ids =
  6. from(j in Oban.Job,
  7. where: j.queue == "activity_expiration",
  8. where: j.worker == "Pleroma.Workers.PurgeExpiredActivity",
  9. where: j.state == "scheduled",
  10. select:
  11. {fragment("(?)->>'activity_id'", j.args), fragment("array_agg(?)", j.id), count(j.id)},
  12. group_by: fragment("(?)->>'activity_id'", j.args),
  13. having: count(j.id) > 1
  14. )
  15. |> Pleroma.Repo.all()
  16. |> Enum.map(fn {_, ids, _} ->
  17. max_id = Enum.max(ids)
  18. List.delete(ids, max_id)
  19. end)
  20. |> List.flatten()
  21. from(j in Oban.Job, where: j.id in ^duplicate_ids)
  22. |> Pleroma.Repo.delete_all()
  23. end
  24. def down, do: :noop
  25. end