simplify the prune functions in Pleroma.Activity.Pruner

This commit is contained in:
faried nawaz 2023-09-24 18:34:37 +05:00
parent ec1c2d8236
commit ea4a232d5d
No known key found for this signature in database
GPG key ID: EDCFAF5BA3A2F622

View file

@ -7,29 +7,15 @@ defmodule Pleroma.Activity.Pruner do
alias Pleroma.Repo
import Ecto.Query
def prune_deletes do
def prune_deletes, do: prune("Delete")
def prune_undos, do: prune("Undo")
def prune_removes, do: prune("Remove")
defp prune(activity_type) do
before_time = cutoff()
from(a in Activity,
where: fragment("?->>'type' = ?", a.data, "Delete") and a.inserted_at < ^before_time
)
|> Repo.delete_all(timeout: :infinity)
end
def prune_undos do
before_time = cutoff()
from(a in Activity,
where: fragment("?->>'type' = ?", a.data, "Undo") and a.inserted_at < ^before_time
)
|> Repo.delete_all(timeout: :infinity)
end
def prune_removes do
before_time = cutoff()
from(a in Activity,
where: fragment("?->>'type' = ?", a.data, "Remove") and a.inserted_at < ^before_time
where: fragment("?->>'type' = ?", a.data, ^activity_type) and a.inserted_at < ^before_time
)
|> Repo.delete_all(timeout: :infinity)
end