PERF: Don't do initialization for every DB if RAILS_DB is set (#28668)

This commit is contained in:
Daniel Waterworth 2024-09-03 00:56:46 -05:00 committed by GitHub
parent a455567f9e
commit baf41790dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -81,7 +81,7 @@ store.redis_prefix = Proc.new { redis.namespace }
store.redis_raw_connection = redis.without_namespace
severities = [Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN]
RailsMultisite::ConnectionManagement.each_connection do
RailsMultisite::ConnectionManagement.safe_each_connection do
error_rate_per_minute =
begin
SiteSetting.alert_admins_if_errors_per_minute

View File

@ -2,8 +2,16 @@
module RailsMultisite
class ConnectionManagement
def self.each_active_connection(&blk)
if ENV["RAILS_DB"]
blk.call(current_db)
else
each_connection(&blk)
end
end
def self.safe_each_connection
self.each_connection do |db|
each_active_connection do |db|
begin
yield(db) if block_given?
rescue PG::ConnectionBad, PG::UnableToSend, PG::ServerError