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.
This commit is contained in:
Guo Xiang Tan 2018-12-17 17:27:44 +08:00
parent 9e795b9d90
commit c0aae16f6b
3 changed files with 11 additions and 2 deletions

View File

@ -125,10 +125,12 @@ class Site
json json
end end
SITE_JSON_CHANNEL = '/site_json'
def self.clear_anon_cache! def self.clear_anon_cache!
# publishing forces the sequence up # publishing forces the sequence up
# the cache is validated based on the sequence # the cache is validated based on the sequence
MessageBus.publish('/site_json', '') MessageBus.publish(SITE_JSON_CHANNEL, '')
end end
end end

View File

@ -346,6 +346,7 @@ module Discourse
def self.disable_readonly_mode(key = READONLY_MODE_KEY) def self.disable_readonly_mode(key = READONLY_MODE_KEY)
$redis.del(key) $redis.del(key)
MessageBus.publish(readonly_channel, false) MessageBus.publish(readonly_channel, false)
Site.clear_anon_cache!
true true
end end

View File

@ -190,11 +190,17 @@ describe Discourse do
describe ".disable_readonly_mode" do describe ".disable_readonly_mode" do
it "removes a key from redis and publish a message through the message bus" do it "removes a key from redis and publish a message through the message bus" do
Discourse.enable_readonly_mode Discourse.enable_readonly_mode
message = nil
message = get_readonly_message do messages = MessageBus.track_publish do
Discourse.disable_readonly_mode Discourse.disable_readonly_mode
end 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) assert_readonly_mode_disabled(message, readonly_mode_key)
end end