Class: Rack::Bug::SphinxPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/sphinx_panel.rb,
lib/rack/bug/panels/sphinx_panel/stats.rb

Defined Under Namespace

Classes: Stats

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #before, #call, #has_content?, #initialize, #panel_app, #render

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

This class inherits a constructor from Rack::Bug::Panel

Class Method Details

.record(*sphinx_command_args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 9

def self.record(*sphinx_command_args, &block)
  return block.call unless Rack::Bug.enabled?

  start_time = Time.now
  result = block.call
  total_time = Time.now - start_time
  stats.record_call(total_time * 1_000, sphinx_command_args)
  return result
end

.resetObject



19
20
21
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 19

def self.reset
  Thread.current["rack.bug.sphinx"] = Stats.new
end

.statsObject



23
24
25
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 23

def self.stats
  Thread.current["rack.bug.sphinx"] ||= Stats.new
end

Instance Method Details

#contentObject



35
36
37
38
39
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 35

def content
  result = render_template "panels/sphinx", :stats => self.class.stats
  self.class.reset
  return result
end

#headingObject



31
32
33
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 31

def heading
  "Sphinx: %.2fms (#{self.class.stats.queries.size} calls)" % self.class.stats.time
end

#nameObject



27
28
29
# File 'lib/rack/bug/panels/sphinx_panel.rb', line 27

def name
  "sphinx"
end