Also prune removes and undos
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
ci/woodpecker/pr/woodpecker Pipeline is pending

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. 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 @@ def prune_deletes do
|> Repo.delete_all(timeout: :infinity) |> Repo.delete_all(timeout: :infinity)
end 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 defp cutoff do
DateTime.utc_now() |> Timex.shift(days: -@cutoff) DateTime.utc_now() |> Timex.shift(days: -@cutoff)
end end

View file

@ -15,6 +15,12 @@ def perform(_job) do
Logger.info("Pruning old deletes") Logger.info("Pruning old deletes")
ActivityPruner.prune_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") Logger.info("Pruning old tombstone delivery entries")
ObjectPruner.prune_tombstoned_deliveries() ObjectPruner.prune_tombstoned_deliveries()