diff --git a/docker/app/run-development b/docker/app/run-development index d593f820..2990b9a5 100755 --- a/docker/app/run-development +++ b/docker/app/run-development @@ -9,6 +9,7 @@ background() { mix run -e 'Philomena.Release.update_channels()' mix run -e 'Philomena.Release.verify_artist_links()' mix run -e 'Philomena.Release.update_stats()' + mix run -e 'Philomena.Release.clean_moderation_logs()' sleep 300 done diff --git a/lib/philomena/moderation_logs.ex b/lib/philomena/moderation_logs.ex index 3c7593e7..dcdb53f4 100644 --- a/lib/philomena/moderation_logs.ex +++ b/lib/philomena/moderation_logs.ex @@ -74,4 +74,10 @@ defmodule Philomena.ModerationLogs do def delete_moderation_log(%ModerationLog{} = moderation_log) do Repo.delete(moderation_log) end + + def cleanup! do + ModerationLog + |> where([ml], ml.created_at < ago(2, "week")) + |> Repo.delete_all() + end end diff --git a/lib/philomena/release.ex b/lib/philomena/release.ex index 4820775d..8963bff2 100644 --- a/lib/philomena/release.ex +++ b/lib/philomena/release.ex @@ -29,6 +29,11 @@ defmodule Philomena.Release do PhilomenaWeb.StatsUpdater.update_stats!() end + def clean_moderation_logs do + start_app() + Philomena.ModerationLogs.cleanup!() + end + defp repos do Application.fetch_env!(@app, :ecto_repos) end