Class: SqlMonitor::TrackingSqlsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/sql_monitor/tracking_sqls_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/sql_monitor/tracking_sqls_controller.rb', line 15

def index
  return not_found if Rails.env.production? || SqlMonitor.handler.nil?

  @versions = SqlMonitor.handler.redis.get('all_versions')
  if @versions.nil? || @versions.empty?
    @versions = []
  else
    @versions = JSON.parse(SqlMonitor.handler.redis.get('all_versions'), {:symbolize_names => true})
  end

  @data = []
  @selectedVersion = ''
  if params[:version]
    data = []
    @selectedVersion = params[:version]
    SqlMonitor.handler.redis.scan_each(match: @selectedVersion + ":*") do |v|
      data << JSON.parse(SqlMonitor.handler.redis.mGet(v).first, {:symbolize_names => true}).merge({sql_key: v.split(':')[1]})
    end
    @data = format_data(sort_data(data, 'count'))
  end
end

#not_foundObject



9
10
11
12
13
# File 'app/controllers/sql_monitor/tracking_sqls_controller.rb', line 9

def not_found
  respond_to do |format|
    format.any  { head :not_found }
  end
end