2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-30 06:01:06 -05:00
|
|
|
# we want MesageBus to be close to the front
|
2015-12-08 18:48:41 -06:00
|
|
|
# this is important cause the vast majority of web requests go to it
|
|
|
|
# this allows us to avoid full middleware crawls each time
|
2020-03-30 06:01:06 -05:00
|
|
|
#
|
|
|
|
# We aren't manipulating the middleware stack directly because of
|
|
|
|
# https://github.com/rails/rails/pull/27936
|
2017-09-04 07:42:22 -05:00
|
|
|
|
2020-05-07 19:44:51 -05:00
|
|
|
Rails.configuration.middleware.unshift(MessageBus::Rack::Middleware)
|
2015-12-08 18:48:41 -06:00
|
|
|
|
|
|
|
# no reason to track this in development, that is 300+ redis calls saved per
|
|
|
|
# page view (we serve all assets out of thin in development)
|
|
|
|
if Rails.env != 'development' || ENV['TRACK_REQUESTS']
|
|
|
|
require 'middleware/request_tracker'
|
|
|
|
Rails.configuration.middleware.unshift Middleware::RequestTracker
|
2019-06-05 01:08:11 -05:00
|
|
|
|
|
|
|
if GlobalSetting.enable_performance_http_headers
|
|
|
|
MethodProfiler.ensure_discourse_instrumentation!
|
|
|
|
end
|
2015-12-08 18:48:41 -06:00
|
|
|
end
|
2020-03-30 06:01:06 -05:00
|
|
|
|
|
|
|
if Rails.configuration.multisite
|
2020-05-07 19:44:51 -05:00
|
|
|
# Multisite needs to be first, because the request tracker and message bus rely on it
|
|
|
|
Rails.configuration.middleware.unshift RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config
|
|
|
|
Rails.configuration.middleware.delete ActionDispatch::Executor
|
2020-03-30 06:01:06 -05:00
|
|
|
end
|
2020-06-04 04:13:59 -05:00
|
|
|
|
|
|
|
if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
2020-06-04 07:29:47 -05:00
|
|
|
if Rails.configuration.multisite
|
|
|
|
Rails.configuration.middleware.move_after(RailsMultisite::Middleware, RailsFailover::ActiveRecord::Middleware)
|
|
|
|
else
|
|
|
|
Rails.configuration.middleware.move_before(MessageBus::Rack::Middleware, RailsFailover::ActiveRecord::Middleware)
|
|
|
|
end
|
2020-06-04 04:13:59 -05:00
|
|
|
end
|