Revert "REFACTOR: Move the multisite middleware to the front"

Looks like this is causing problems.

Follow-up-to: a91843f0dc
This commit is contained in:
Daniel Waterworth 2020-04-02 15:19:42 +01:00
parent 41510d5b84
commit ca1208a636
3 changed files with 24 additions and 21 deletions

View File

@ -26,3 +26,11 @@ module RailsMultisite
end
end
end
if Rails.configuration.multisite
Rails.configuration.middleware.swap(
RailsMultisite::Middleware,
RailsMultisite::Middleware,
RailsMultisite::DiscoursePatches.config
)
end

View File

@ -1,11 +1,9 @@
# frozen_string_literal: true
# we want MesageBus to be close to the front
# we want MesageBus in the absolute front
# this is important cause the vast majority of web requests go to it
# this allows us to avoid full middleware crawls each time
#
# We aren't manipulating the middleware stack directly because of
# https://github.com/rails/rails/pull/27936
# Pending https://github.com/rails/rails/pull/27936
session_operations = Rails::Configuration::MiddlewareStackProxy.new([
[:delete, MessageBus::Rack::Middleware],
[:unshift, MessageBus::Rack::Middleware],
@ -23,14 +21,3 @@ if Rails.env != 'development' || ENV['TRACK_REQUESTS']
MethodProfiler.ensure_discourse_instrumentation!
end
end
if Rails.configuration.multisite
# Multisite needs to be first, because the request tracker and message bus
# rely on it
session_operations = Rails::Configuration::MiddlewareStackProxy.new([
[:delete, RailsMultisite::Middleware],
[:unshift, RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config],
])
Rails.configuration.middleware = Rails.configuration.middleware + session_operations
end

View File

@ -51,6 +51,14 @@ class Middleware::RequestTracker
@app = app
end
def self.log_request_on_site(data, host)
RailsMultisite::ConnectionManagement.with_hostname(host) do
unless Discourse.pg_readonly_mode?
log_request(data)
end
end
end
def self.log_request(data)
status = data[:status]
track_view = data[:track_view]
@ -127,6 +135,7 @@ class Middleware::RequestTracker
# we got to skip this on error ... its just logging
data = self.class.get_data(env, result, info) rescue nil
host = RailsMultisite::ConnectionManagement.host(env)
if data
if result && (headers = result[1])
@ -137,7 +146,7 @@ class Middleware::RequestTracker
@@detailed_request_loggers.each { |logger| logger.call(env, data) }
end
log_later(data)
log_later(data, host)
end
end
@ -287,11 +296,10 @@ class Middleware::RequestTracker
end
end
def log_later(data)
Scheduler::Defer.later("Track view") do
unless Discourse.pg_readonly_mode?
self.class.log_request(data)
end
def log_later(data, host)
Scheduler::Defer.later("Track view", _db = nil) do
self.class.log_request_on_site(data, host)
end
end
end