Class: RailsPerformance::Rails::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/rails/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
# File 'lib/rails_performance/rails/middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
# File 'lib/rails_performance/rails/middleware.rb', line 8

def call(env)
  dup.call!(env)
end

#call!(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_performance/rails/middleware.rb', line 12

def call!(env)
  @status, @headers, @response = @app.call(env)

  #t = Time.now
  if record = CurrentRequest.current.record
    begin
      record[:status]   ||= @status # for 500 errors
      record[:request_id] = CurrentRequest.current.request_id

      # capture referer from where this page was opened
      if record[:status] == 404
        record[:HTTP_REFERER] = env["HTTP_REFERER"]
      end

      # store for section "recent requests"
      RP::Utils.log_trace_in_redis(CurrentRequest.current.request_id, CurrentRequest.current.storage)

      # store request information
      RP::Utils.log_request_in_redis(record)
    ensure
      # we don't want to have a memory leak
      CurrentRequest.cleanup
    end
  end
  #puts "==> store performance data: #{(Time.now - t).round(3)}ms"

  [@status, @headers, @response]
end