aboutsummaryrefslogtreecommitdiff
path: root/lib/mix
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2019-05-21 01:21:28 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2019-05-21 21:38:56 +0000
commit16b260fb19cca02463766c2e36a41bfcc823af9b (patch)
tree108aa2a1daf502d11f25535dcfe728e2ba3c07a9 /lib/mix
parent73df9d690d5c1a9c11f0f04b8d877c0677022591 (diff)
downloadpleroma-16b260fb19cca02463766c2e36a41bfcc823af9b.tar.gz
add mix task to prune the object database using a configured retention period
Diffstat (limited to 'lib/mix')
-rw-r--r--lib/mix/tasks/pleroma/database.ex40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex
index f650b447d..fdb216037 100644
--- a/lib/mix/tasks/pleroma/database.ex
+++ b/lib/mix/tasks/pleroma/database.ex
@@ -23,6 +23,10 @@ defmodule Mix.Tasks.Pleroma.Database do
Options:
- `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references
+ ## Prune old objects from the database
+
+ mix pleroma.database prune_objects
+
## Create a conversation for all existing DMs. Can be safely re-run.
mix pleroma.database bump_all_conversations
@@ -72,4 +76,40 @@ defmodule Mix.Tasks.Pleroma.Database do
Enum.each(users, &User.remove_duplicated_following/1)
Enum.each(users, &User.update_follower_count/1)
end
+
+ def run(["prune_objects" | args]) do
+ {options, [], []} =
+ OptionParser.parse(
+ args,
+ strict: [
+ vacuum: :boolean
+ ]
+ )
+
+ Common.start_pleroma()
+
+ deadline = Pleroma.Config.get([:instance, :remote_post_retention_days])
+
+ Logger.info("Pruning objects older than #{deadline} days")
+
+ time_deadline =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(-(deadline * 86_400))
+
+ Repo.query!(
+ "DELETE FROM objects WHERE inserted_at < $1 AND split_part(data->>'actor', '/', 3) != $2",
+ [time_deadline, Pleroma.Web.Endpoint.host()],
+ timeout: :infinity
+ )
+
+ if Keyword.get(options, :vacuum) do
+ Logger.info("Runnning VACUUM FULL")
+
+ Repo.query!(
+ "vacuum full;",
+ [],
+ timeout: :infinity
+ )
+ end
+ end
end