From c0aae16f6bdf97180e407f5a8213dfbd389fe9af Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 17 Dec 2018 17:27:44 +0800 Subject: [PATCH] FIX: Clear anon cache when disabling readonly mode. `SiteSerializer#is_readonly` is cached for an anonymous user so we have to clear the cache when disabling readonly mode. Otherwise, the site may appear to be in readonly mode for an extended period of time. --- app/models/site.rb | 4 +++- lib/discourse.rb | 1 + spec/components/discourse_spec.rb | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 8577329d67f..cdc34c2ef80 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -125,10 +125,12 @@ class Site json end + SITE_JSON_CHANNEL = '/site_json' + def self.clear_anon_cache! # publishing forces the sequence up # the cache is validated based on the sequence - MessageBus.publish('/site_json', '') + MessageBus.publish(SITE_JSON_CHANNEL, '') end end diff --git a/lib/discourse.rb b/lib/discourse.rb index 21a3e3341df..149b2f5b203 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -346,6 +346,7 @@ module Discourse def self.disable_readonly_mode(key = READONLY_MODE_KEY) $redis.del(key) MessageBus.publish(readonly_channel, false) + Site.clear_anon_cache! true end diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index 5d53b71f370..068dad383df 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -190,11 +190,17 @@ describe Discourse do describe ".disable_readonly_mode" do it "removes a key from redis and publish a message through the message bus" do Discourse.enable_readonly_mode + message = nil - message = get_readonly_message do + messages = MessageBus.track_publish do Discourse.disable_readonly_mode end + expect(messages.any? { |m| m.channel == Site::SITE_JSON_CHANNEL }) + .to eq(true) + + message = messages.find { |m| m.channel == Discourse.readonly_channel } + assert_readonly_mode_disabled(message, readonly_mode_key) end