mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 14:03:39 +08:00
BUGFIX: proper multisite support for origin pull CDNs
This commit is contained in:
parent
18bdc4e63e
commit
0c86d9ed9e
|
@ -416,7 +416,7 @@ Discourse.User = Discourse.Model.extend({
|
|||
Discourse.User.reopenClass(Discourse.Singleton, {
|
||||
|
||||
avatarTemplate: function(username, uploadedAvatarId){
|
||||
var url = Discourse.getURL("/user_avatar/" + username.toLowerCase() + "/{size}/" + uploadedAvatarId + ".png");
|
||||
var url = Discourse.getURL("/user_avatar/" + Discourse.BaseUrl + "/" + username.toLowerCase() + "/{size}/" + uploadedAvatarId + ".png");
|
||||
if(Discourse.CDN){
|
||||
url = Discourse.CDN + url;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,16 @@ class UserAvatarsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
# we need multisite support to keep a single origin pull for CDNs
|
||||
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
||||
show_in_site
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def show_in_site
|
||||
username = params[:username].to_s
|
||||
return render_dot unless user = User.find_by(username_lower: username.downcase)
|
||||
|
||||
|
@ -62,7 +70,6 @@ class UserAvatarsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# this protects us from a DoS
|
||||
def render_dot
|
||||
|
|
|
@ -212,7 +212,7 @@ Discourse::Application.routes.draw do
|
|||
delete "users/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
||||
post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar"
|
||||
get "user_avatar/:username/:size/:version.png" => "user_avatars#show", format: false
|
||||
get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false
|
||||
|
||||
|
||||
get "uploads/:site/:id/:sha.:extension" => "uploads#show", constraints: {site: /\w+/, id: /\d+/, sha: /[a-z0-9]{15,16}/i, extension: /\w{2,}/}
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue
Block a user