2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

BUGFIX: proper multisite support for origin pull CDNs

This commit is contained in:
Sam 2014-05-27 23:13:42 +10:00
parent 18bdc4e63e
commit 0c86d9ed9e
4 changed files with 35 additions and 4 deletions

View file

@ -37,6 +37,30 @@ module RailsMultisite
end
end
def self.with_hostname(hostname)
unless defined? @@db_spec_cache
# just fake it for non multisite
yield hostname
return
end
old = current_hostname
connected = ActiveRecord::Base.connection_pool.connected?
establish_connection(:hostname => hostname) unless connected && hostname == old
rval = yield hostname
unless connected && hostname == old
ActiveRecord::Base.connection_handler.clear_active_connections!
establish_connection(:hostname => old)
ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
end
rval
end
def self.with_connection(db = "default")
old = current_db
connected = ActiveRecord::Base.connection_pool.connected?