diff options
author | feld <feld@feld.me> | 2021-02-02 17:22:23 +0000 |
---|---|---|
committer | feld <feld@feld.me> | 2021-02-02 17:22:23 +0000 |
commit | 6a2d3fb9a3775fc0e167c71bb8a8fba3608b2f17 (patch) | |
tree | 83a3e4164997001d9910750cb23e1c7fca941172 /priv | |
parent | b36891d1e6f5d4b0874ef19c4418a46d580c4701 (diff) | |
parent | 22486fb4af49214fb2b0eff09f00006fbfdd9745 (diff) |
Merge branch 'fix/2473-purge-expired-activities-duplicates' into 'develop'
fix and delete purge activities duplicates
Closes #2473
See merge request pleroma/pleroma!3285
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs new file mode 100644 index 000000000..309009205 --- /dev/null +++ b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs @@ -0,0 +1,29 @@ +defmodule Pleroma.Repo.Migrations.RemoveDuplicatesFromActivityExpirationQueue do + use Ecto.Migration + + import Ecto.Query, only: [from: 2] + + def up do + duplicate_ids = + from(j in Oban.Job, + where: j.queue == "activity_expiration", + where: j.worker == "Pleroma.Workers.PurgeExpiredActivity", + where: j.state == "scheduled", + select: + {fragment("(?)->>'activity_id'", j.args), fragment("array_agg(?)", j.id), count(j.id)}, + group_by: fragment("(?)->>'activity_id'", j.args), + having: count(j.id) > 1 + ) + |> Pleroma.Repo.all() + |> Enum.map(fn {_, ids, _} -> + max_id = Enum.max(ids) + List.delete(ids, max_id) + end) + |> List.flatten() + + from(j in Oban.Job, where: j.id in ^duplicate_ids) + |> Pleroma.Repo.delete_all() + end + + def down, do: :noop +end |