class RailsPerformance::Rails::Middleware
Public Class Methods
new(app)
click to toggle source
# File lib/rails_performance/rails/middleware.rb, line 33 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rails_performance/rails/middleware.rb, line 37 def call(env) dup.call!(env) end
call!(env)
click to toggle source
# File lib/rails_performance/rails/middleware.rb, line 41 def call!(env) @status, @headers, @response = @app.call(env) #t = Time.now if !RailsPerformance.skip if !CurrentRequest.current.ignore.include?(:performance) # grape is executed first, and than ignore regular future storage of "controller"-like request if data = CurrentRequest.current.data record = RailsPerformance::Models::RequestRecord.new(**data.merge({request_id: CurrentRequest.current.request_id})) # for 500 errors record.status ||= @status # capture referer from where this page was opened record.http_referer = env["HTTP_REFERER"] if record.status == 404 # store for section "recent requests" # store request information (regular rails request) record.save end end end #puts "==> store performance data: #{(Time.now - t).round(3)}ms" [@status, @headers, @response] end