From 21b4b8d5d5af5fae9921ba6643dcb775e43a9f2e Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 14 May 2013 16:17:17 -0400 Subject: [PATCH] Expire dashboard data when you upgrade to a new discourse version. Version check data was being cached and causing confusion to people who upgraded. --- app/controllers/admin/dashboard_controller.rb | 13 ++++++++++--- app/models/admin_dashboard_data.rb | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 2b7c74f6bfb..03ba0ac44e4 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,9 +1,16 @@ class Admin::DashboardController < Admin::AdminController - caches_action :index, expires_in: 1.hour - def index - render_json_dump(AdminDashboardData.fetch_all) + # see https://github.com/rails/rails/issues/8167 + # TODO: after upgrading to Rails 4, try to remove "if cache_classes" + if Discourse::Application.config.cache_classes + dashboard_data = Rails.cache.fetch("admin-dashboard-data-#{Discourse::VERSION::STRING}", expires_in: 1.hour) do + AdminDashboardData.fetch_all.as_json + end + render json: dashboard_data + else + render_json_dump AdminDashboardData.fetch_all + end end def problems diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index a7821356618..a4e0513ee08 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -45,13 +45,13 @@ class AdminDashboardData def as_json @json ||= { - reports: REPORTS.map { |type| Report.find(type) }, + reports: REPORTS.map { |type| Report.find(type).as_json }, problems: problems, admins: User.admins.count, moderators: User.moderators.count, - top_referrers: IncomingLinksReport.find('top_referrers'), - top_traffic_sources: IncomingLinksReport.find('top_traffic_sources'), - top_referred_topics: IncomingLinksReport.find('top_referred_topics') + top_referrers: IncomingLinksReport.find('top_referrers').as_json, + top_traffic_sources: IncomingLinksReport.find('top_traffic_sources').as_json, + top_referred_topics: IncomingLinksReport.find('top_referred_topics').as_json }.merge( SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {} )