diff --git a/lib/discourse.rb b/lib/discourse.rb index 79e59845982..d36f46c2b26 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -295,7 +295,7 @@ module Discourse # extend the expiry by 1 minute every 30 seconds unless Rails.env.test? Thread.new do - while readonly_mode? + while readonly_mode?(key) $redis.expire(key, READONLY_MODE_KEY_TTL) sleep 30.seconds end @@ -309,8 +309,8 @@ module Discourse true end - def self.readonly_mode? - recently_readonly? || $redis.mget(*READONLY_KEYS).compact.present? + def self.readonly_mode?(keys = READONLY_KEYS) + recently_readonly? || $redis.mget(*keys).compact.present? end def self.last_read_only diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index b9ef0df7d9f..64d3c6c112b 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -177,6 +177,7 @@ describe Discourse do it "returns true when user enabled readonly mode key is present in redis" do Discourse.enable_readonly_mode(user_readonly_mode_key) expect(Discourse.readonly_mode?).to eq(true) + expect(Discourse.readonly_mode?(readonly_mode_key)).to eq(false) Discourse.disable_readonly_mode(user_readonly_mode_key) expect(Discourse.readonly_mode?).to eq(false)