1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.RemoveDuplicatesFromActivityExpirationQueue do
8 import Ecto.Query, only: [from: 2]
13 where: j.queue == "activity_expiration",
14 where: j.worker == "Pleroma.Workers.PurgeExpiredActivity",
15 where: j.state == "scheduled",
17 {fragment("(?)->>'activity_id'", j.args), fragment("array_agg(?)", j.id), count(j.id)},
18 group_by: fragment("(?)->>'activity_id'", j.args),
19 having: count(j.id) > 1
22 |> Enum.map(fn {_, ids, _} ->
23 max_id = Enum.max(ids)
24 List.delete(ids, max_id)
28 from(j in Oban.Job, where: j.id in ^duplicate_ids)
29 |> Pleroma.Repo.delete_all()