From 41c1e1b30222b6fac8b5e56323d4f5a7b9ae1509 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 19 Jun 2018 15:44:08 +0800 Subject: [PATCH] FIX: `Discourse.keep_readonly_mode` does not work for multisite. --- lib/discourse.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/discourse.rb b/lib/discourse.rb index f42caae4f49..83e95d51311 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -294,15 +294,24 @@ module Discourse def self.keep_readonly_mode(key) # extend the expiry by 1 minute every 30 seconds unless Rails.env.test? + @dbs ||= Set.new + @dbs << RailsMultisite::ConnectionManagement.current_db @threads ||= {} - active_thread = @threads[key] - - unless active_thread&.alive? + unless @threads[key]&.alive? @threads[key] = Thread.new do - while readonly_mode?(key) - $redis.expire(key, READONLY_MODE_KEY_TTL) - sleep 30.seconds + while @dbs.size > 0 + @dbs.each do |db| + RailsMultisite::ConnectionManagement.with_connection(db) do + if readonly_mode?(key) + $redis.expire(key, READONLY_MODE_KEY_TTL) + else + @dbs.delete(db) + end + end + end + + sleep 30 end end end