Class: RailsPerformance::Rails::Middleware
- Inherits:
-
Object
- Object
- RailsPerformance::Rails::Middleware
- Defined in:
- lib/rails_performance/rails/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
33 34 35 |
# File 'lib/rails_performance/rails/middleware.rb', line 33 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 |
# File 'lib/rails_performance/rails/middleware.rb', line 37 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 |