logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20200914105638_delete_notification_without_activity.exs (797B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.DeleteNotificationWithoutActivity do
  5. use Ecto.Migration
  6. import Ecto.Query
  7. alias Pleroma.Repo
  8. def up do
  9. from(
  10. q in Pleroma.Notification,
  11. left_join: c in assoc(q, :activity),
  12. select: %{id: type(q.id, :integer)},
  13. where: is_nil(c.id)
  14. )
  15. |> Repo.chunk_stream(1_000, :batches)
  16. |> Stream.each(fn records ->
  17. notification_ids = Enum.map(records, fn %{id: id} -> id end)
  18. Repo.delete_all(
  19. from(n in "notifications",
  20. where: n.id in ^notification_ids
  21. )
  22. )
  23. end)
  24. |> Stream.run()
  25. end
  26. def down do
  27. :ok
  28. end
  29. end