FIX: Discouse.keep_readonly_mode incorrect extends expiry.

This commit is contained in:
Guo Xiang Tan 2018-06-12 00:21:29 +08:00
parent 2adae2a0b6
commit bfa0f71e2b
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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)