mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 10:15:49 +08:00
62141b6316
This adds support for DISCOURSE_ENABLE_PERFORMANCE_HTTP_HEADERS when set to `true` this will turn on performance related headers ```text X-Redis-Calls: 10 # number of redis calls X-Redis-Time: 1.02 # redis time in seconds X-Sql-Commands: 102 # number of SQL commands X-Sql-Time: 1.02 # duration in SQL in seconds X-Queue-Time: 1.01 # time the request sat in queue (depends on NGINX) ``` To get queue time NGINX must provide: HTTP_X_REQUEST_START We do not recommend you enable this without thinking, it exposes information about what your page is doing, usually you would only enable this if you intend to strip off the headers further down the stream in a proxy
24 lines
917 B
Ruby
24 lines
917 B
Ruby
# frozen_string_literal: true
|
|
|
|
# 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
|
|
# Pending https://github.com/rails/rails/pull/27936
|
|
session_operations = Rails::Configuration::MiddlewareStackProxy.new([
|
|
[:delete, MessageBus::Rack::Middleware],
|
|
[:unshift, MessageBus::Rack::Middleware],
|
|
])
|
|
|
|
Rails.configuration.middleware = Rails.configuration.middleware + session_operations
|
|
|
|
# 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
|
|
|
|
if GlobalSetting.enable_performance_http_headers
|
|
MethodProfiler.ensure_discourse_instrumentation!
|
|
end
|
|
end
|