From d28d81a590f7bd0c8436ee8f5fa33c0c59561615 Mon Sep 17 00:00:00 2001
From: Neil Lalonde <neillalonde@gmail.com>
Date: Wed, 20 Mar 2013 16:16:23 -0400
Subject: [PATCH] Dashboard warning when GC params are default

---
 .../admin/templates/dashboard.js.handlebars        |  2 +-
 app/models/admin_dashboard_data.rb                 |  6 +++++-
 config/locales/server.en.yml                       |  1 +
 spec/models/admin_dashboard_data_spec.rb           | 14 ++++++++++++++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/app/assets/javascripts/admin/templates/dashboard.js.handlebars b/app/assets/javascripts/admin/templates/dashboard.js.handlebars
index 04858ad3d..977dbe027 100644
--- a/app/assets/javascripts/admin/templates/dashboard.js.handlebars
+++ b/app/assets/javascripts/admin/templates/dashboard.js.handlebars
@@ -7,7 +7,7 @@
           {{i18n admin.dashboard.problems_found}}
           <ul>
             {{#each problem in problems}}
-              <li>{{problem}}</li>
+              <li>{{{problem}}}</li>
             {{/each}}
           </ul>
         </p>
diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb
index 8dac0e953..29f445361 100644
--- a/app/models/admin_dashboard_data.rb
+++ b/app/models/admin_dashboard_data.rb
@@ -10,7 +10,7 @@ class AdminDashboardData
     @json ||= {
       reports: REPORTS.map { |type| Report.find(type) },
       total_users: User.count,
-      problems: [rails_env_check, host_names_check].compact
+      problems: [rails_env_check, host_names_check, gc_checks].compact
     }.merge(
       SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
     )
@@ -23,4 +23,8 @@ class AdminDashboardData
   def host_names_check
     I18n.t("dashboard.host_names_warning") if ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
   end
+
+  def gc_checks
+    I18n.t("dashboard.gc_warning") if ENV['RUBY_GC_MALLOC_LIMIT'].nil?
+  end
 end
\ No newline at end of file
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index c0f91f726..f5ff79b24 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -286,6 +286,7 @@ en:
   dashboard:
     rails_env_warning: "Your server is running in %{env} mode."
     host_names_warning: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname."
+    gc_warning: 'Your server is using default ruby garbage collection parameters, which will not give you the best performance. Read this topic on performance tuning: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
 
   site_settings:
     default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rb
index b5c604abe..9020b955d 100644
--- a/spec/models/admin_dashboard_data_spec.rb
+++ b/spec/models/admin_dashboard_data_spec.rb
@@ -40,4 +40,18 @@ describe AdminDashboardData do
     end
   end
 
+  describe 'gc_checks' do
+    subject { AdminDashboardData.new.gc_checks }
+
+    it 'returns nil when gc params are set' do
+      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
+      subject.should be_nil
+    end
+
+    it 'returns a string when gc params are not set' do
+      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(nil)
+      subject.should_not be_nil
+    end
+  end
+
 end
\ No newline at end of file