Also prune removes and undos
ci/woodpecker/push/woodpecker Pipeline is pending Details
ci/woodpecker/pr/woodpecker Pipeline is pending Details

This commit is contained in:
FloatingGhost 2022-12-01 12:58:57 +00:00
parent e747f164d4
commit 4d1a18537e
3 changed files with 44 additions and 0 deletions

View File

@ -159,3 +159,23 @@ Change `default_text_search_config` for database and (if necessary) text_search_
```
See [PostgreSQL documentation](https://www.postgresql.org/docs/current/textsearch-configuration.html) and `docs/configuration/howto_search_cjk.md` for more detail.
## Pruning old activities
Over time, transient `Delete` activities and `Tombstone` objects
can accumulate in your database, inflating its size. This is not ideal.
There is a periodic task to prune these transient objects,
but on first run this may take a while on older instances to catch up
to the current day.
=== "OTP"
```sh
./bin/pleroma_ctl database prune_task
```
=== "From Source"
```sh
mix pleroma.database prune_task
```

View File

@ -17,6 +17,24 @@ defmodule Pleroma.Activity.Pruner do
|> 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

View File

@ -15,6 +15,12 @@ defmodule Pleroma.Workers.Cron.PruneDatabaseWorker do
Logger.info("Pruning old deletes")
ActivityPruner.prune_deletes()
Logger.info("Pruning old undos")
ActivityPruner.prune_undos()
Logger.info("Pruning old removes")
ActivityPruner.prune_removes()
Logger.info("Pruning old tombstone delivery entries")
ObjectPruner.prune_tombstoned_deliveries()