forked from AkkomaGang/akkoma
floatingghost
db60640c5b
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: AkkomaGang/akkoma#327
41 lines
923 B
Elixir
41 lines
923 B
Elixir
defmodule Pleroma.Activity.Pruner do
|
|
@moduledoc """
|
|
Prunes activities from the database.
|
|
"""
|
|
@cutoff 30
|
|
|
|
alias Pleroma.Activity
|
|
alias Pleroma.Repo
|
|
import Ecto.Query
|
|
|
|
def prune_deletes 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
|
|
)
|
|
|> Repo.delete_all(timeout: :infinity)
|
|
end
|
|
|
|
defp cutoff do
|
|
DateTime.utc_now() |> Timex.shift(days: -@cutoff)
|
|
end
|
|
end
|