maintenance: prune posts hourly instead of daily.

This commit is contained in:
evazion
2020-08-07 09:10:00 -05:00
parent 3b73861d05
commit 8917cc3035
2 changed files with 6 additions and 4 deletions

View File

@@ -3,10 +3,10 @@ module DanbooruMaintenance
def hourly def hourly
safely { Upload.prune! } safely { Upload.prune! }
safely { PostPruner.prune! }
end end
def daily def daily
safely { PostPruner.prune! }
safely { Delayed::Job.where('created_at < ?', 45.days.ago).delete_all } safely { Delayed::Job.where('created_at < ?', 45.days.ago).delete_all }
safely { PostDisapproval.prune! } safely { PostDisapproval.prune! }
safely { regenerate_post_counts! } safely { regenerate_post_counts! }

View File

@@ -1,9 +1,9 @@
require 'test_helper' require 'test_helper'
class DanbooruMaintenanceTest < ActiveSupport::TestCase class DanbooruMaintenanceTest < ActiveSupport::TestCase
context "daily maintenance" do context "hourly maintenance" do
should "work" do should "work" do
assert_nothing_raised { DanbooruMaintenance.daily } assert_nothing_raised { DanbooruMaintenance.hourly }
end end
should "prune expired posts" do should "prune expired posts" do
@@ -14,7 +14,7 @@ class DanbooruMaintenanceTest < ActiveSupport::TestCase
@flag = create(:post_flag, post: @flagged, created_at: 4.days.ago) @flag = create(:post_flag, post: @flagged, created_at: 4.days.ago)
@appeal = create(:post_appeal, post: @appealed, created_at: 4.days.ago) @appeal = create(:post_appeal, post: @appealed, created_at: 4.days.ago)
DanbooruMaintenance.daily DanbooruMaintenance.hourly
assert_equal(true, @pending.reload.is_deleted?) assert_equal(true, @pending.reload.is_deleted?)
assert_equal(true, @flagged.reload.is_deleted?) assert_equal(true, @flagged.reload.is_deleted?)
@@ -22,7 +22,9 @@ class DanbooruMaintenanceTest < ActiveSupport::TestCase
assert_equal(true, @flag.reload.succeeded?) assert_equal(true, @flag.reload.succeeded?)
assert_equal(true, @appeal.reload.rejected?) assert_equal(true, @appeal.reload.rejected?)
end end
end
context "hourly maintenance" do
context "when pruning bans" do context "when pruning bans" do
should "clear the is_banned flag for users who are no longer banned" do should "clear the is_banned flag for users who are no longer banned" do
banner = FactoryBot.create(:admin_user) banner = FactoryBot.create(:admin_user)