- case args do
- "analyze" ->
- Logger.info("Runnning VACUUM ANALYZE.")
- Repo.query!(
- "vacuum analyze;",
- [],
- timeout: :infinity
- )
-
- "full" ->
- Logger.info("Runnning VACUUM FULL. This could take a while.")
-
- Repo.query!(
- "vacuum full;",
- [],
- timeout: :infinity
- )
-
- _ ->
- Logger.error("Error: invalid vacuum argument.")
- end
+ Maintenance.vacuum(args)
+ end
+
+ def run(["ensure_expiration"]) do
+ start_pleroma()
+ days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
+
+ Pleroma.Activity
+ |> join(:left, [a], u in assoc(a, :expiration))
+ |> where(local: true)
+ |> where([a, u], is_nil(u))
+ |> Pleroma.RepoStreamer.chunk_stream(100)
+ |> Stream.each(fn activities ->
+ Enum.each(activities, fn activity ->
+ expires_at = Timex.shift(activity.inserted_at, days: days)
+
+ Pleroma.ActivityExpiration.create(activity, expires_at, false)
+ end)
+ end)
+ |> Stream.run()