diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 85341ac14..c0f558132 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -971,6 +971,8 @@ en: enable_cdn_js_debugging: "Allow /logs to display proper errors by adding crossorigin permissions on all js includes." show_create_topics_notice: "If the site has fewer than 5 public topics, show a notice asking admins to create some topics." + vacuum_db_days: "Run VACUUM FULL ANALYZE to reclaim DB space after migrations (set to 0 to disable)" + errors: invalid_email: "Invalid email address." invalid_username: "There's no user with that username." diff --git a/config/site_settings.yml b/config/site_settings.yml index aa66a28de..67cd795be 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -709,6 +709,11 @@ uncategorized: company_short_name: 'Unconfigured Forum' company_domain: 'www.example.com' + vacuum_db_days: 90 + last_vacuum: + default: 0 + hidden: true + tos_topic_id: default: -1 hidden: true diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 82f2b2392..bc5cc8206 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -2,6 +2,22 @@ task 'db:migrate' => 'environment' do I18n.locale = SiteSetting.default_locale rescue :en SeedFu.seed + + if SiteSetting.vacuum_db_days > 0 && + SiteSetting.last_vacuum < (Time.now.to_i - SiteSetting.vacuum_db_days.days.to_i) + puts "Running VACUUM FULL ANALYZE to reclaim DB space, this may take a while" + puts "Set to run every #{SiteSetting.vacuum_db_days} days (search for vacuum in site settings)" + puts "#{Time.now} starting..." + begin + + Topic.exec_sql("VACUUM FULL ANALYZE") + rescue => e + puts "VACUUM failed, skipping" + puts e.to_s + end + SiteSetting.last_vacuum = Time.now.to_i + puts "#{Time.now} VACUUM done" + end end task 'test:prepare' => 'environment' do