From 06140740d0df412c066f683c4088854a3381ef74 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 30 Jul 2013 12:11:51 -0400 Subject: [PATCH] Version checks: tolerate old version check data that can happen immediately after upgrading but forgetting to restart sidekiq/clockwork. Don't cache version check data along with other dashboard data. --- app/controllers/admin/dashboard_controller.rb | 1 + app/models/admin_dashboard_data.rb | 4 +--- lib/discourse_updates.rb | 17 +++++++++---- lib/jobs/version_check.rb | 2 +- spec/components/discourse_updates_spec.rb | 24 +++++++++++++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 986f15b66a3..1b46c082e2d 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -4,6 +4,7 @@ class Admin::DashboardController < Admin::AdminController dashboard_data = Rails.cache.fetch("admin-dashboard-data-#{Discourse::VERSION::STRING}", expires_in: 1.hour) do AdminDashboardData.fetch_all.as_json end + dashboard_data.merge!({version_check: DiscourseUpdates.check_version.as_json}) if SiteSetting.version_checks? render json: dashboard_data end diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index 9f4a030e8a1..02581e9bf0a 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -59,9 +59,7 @@ class AdminDashboardData 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.as_json} : {} - ) + } end def rails_env_check diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb index 200aed138e7..918c6d1c84b 100644 --- a/lib/discourse_updates.rb +++ b/lib/discourse_updates.rb @@ -20,10 +20,19 @@ module DiscourseUpdates ) end - if version_info.updated_at.nil? or - (version_info.missing_versions_count == 0 and version_info.latest_version != version_info.installed_version) - # Version check data is out of date. - Jobs.enqueue(:version_check, all_sites: true) + if SiteSetting.version_checks? + + # Handle cases when version check data is old so we report something that makes sense + + if (version_info.updated_at.nil? or + (version_info.missing_versions_count == 0 and version_info.latest_version != version_info.installed_version) or + (version_info.missing_versions_count != 0 and version_info.latest_version == version_info.installed_version)) + Jobs.enqueue(:version_check, all_sites: true) + end + + if !version_info.updated_at.nil? and version_info.latest_version == version_info.installed_version + version_info.missing_versions_count = 0 + end end version_info diff --git a/lib/jobs/version_check.rb b/lib/jobs/version_check.rb index 61632f61f1f..5198ad975af 100644 --- a/lib/jobs/version_check.rb +++ b/lib/jobs/version_check.rb @@ -5,7 +5,7 @@ module Jobs class VersionCheck < Jobs::Base def execute(args) - if SiteSetting.version_checks and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago) + if SiteSetting.version_checks? and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago) begin json = DiscourseHub.discourse_version_check DiscourseUpdates.latest_version = json['latestVersion'] diff --git a/spec/components/discourse_updates_spec.rb b/spec/components/discourse_updates_spec.rb index 203a895427f..7e4e96ce8de 100644 --- a/spec/components/discourse_updates_spec.rb +++ b/spec/components/discourse_updates_spec.rb @@ -81,4 +81,28 @@ describe DiscourseUpdates do end end + context 'old version check data' do + context 'installed is latest' do + before { stub_data(Discourse::VERSION::STRING, 1, false, 8.hours.ago) } + + it 'queues a version check' do + Jobs.expects(:enqueue).with(:version_check, anything) + subject + end + + it 'reports 0 missing versions' do + subject['missing_versions_count'].should == 0 + end + end + + context 'installed is not latest' do + before { stub_data('0.9.1', 0, false, 8.hours.ago) } + + it 'queues a version check' do + Jobs.expects(:enqueue).with(:version_check, anything) + subject + end + end + end + end