rack-mini-profiler 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,16 +56,19 @@ module Rack
56
56
  def trim_binds(binds)
57
57
  max_len = Rack::MiniProfiler.config.max_sql_param_length
58
58
  return if binds.nil? || max_len == 0
59
- return binds if max_len.nil?
59
+ return binds.map{|(name, val)| [name, val]} if max_len.nil?
60
60
  binds.map do |(name, val)|
61
61
  val ||= name
62
62
  if val.nil? || val == true || val == false || val.kind_of?(Numeric)
63
63
  # keep these parameters as is
64
64
  elsif val.kind_of?(String)
65
- val = val[0...max_len] if max_len
65
+ val = val[0...max_len]+(max_len < val.length ? '...' : '') if max_len
66
66
  else
67
67
  val = val.class.name
68
68
  end
69
+ if name.kind_of?(String)
70
+ name = name[0...max_len]+(max_len < name.length ? '...' : '') if max_len
71
+ end
69
72
  [name, val]
70
73
  end
71
74
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class MiniProfiler
3
- VERSION = '0.10.2'
3
+ VERSION = '0.10.3'
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@
3
3
  class Mysql2::Result
4
4
  alias_method :each_without_profiling, :each
5
5
  def each(*args, &blk)
6
- return each_without_profiling(*args, &blk) unless @miniprofiler_sql_id
6
+ return each_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id)
7
7
 
8
8
  start = Time.now
9
9
  result = each_without_profiling(*args,&blk)
@@ -1,7 +1,7 @@
1
1
  class ActiveRecord::Result
2
2
  alias_method :each_without_profiling, :each
3
3
  def each(&blk)
4
- return each_without_profiling(&blk) unless @miniprofiler_sql_id
4
+ return each_without_profiling(&blk) unless defined?(@miniprofiler_sql_id)
5
5
 
6
6
  start = Time.now
7
7
  result = each_without_profiling(&blk)
data/lib/patches/db/pg.rb CHANGED
@@ -4,14 +4,14 @@ class PG::Result
4
4
  alias_method :values_without_profiling, :values
5
5
 
6
6
  def values(*args, &blk)
7
- return values_without_profiling(*args, &blk) unless @miniprofiler_sql_id
7
+ return values_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id)
8
8
  mp_report_sql do
9
9
  values_without_profiling(*args ,&blk)
10
10
  end
11
11
  end
12
12
 
13
13
  def each(*args, &blk)
14
- return each_without_profiling(*args, &blk) unless @miniprofiler_sql_id
14
+ return each_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id)
15
15
  mp_report_sql do
16
16
  each_without_profiling(*args, &blk)
17
17
  end
@@ -52,7 +52,7 @@ class PG::Connection
52
52
  start = Time.now
53
53
  result = exec_without_profiling(*args,&blk)
54
54
  elapsed_time = SqlPatches.elapsed_time(start)
55
- record = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)
55
+ record = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time, get_binds(*args))
56
56
  result.instance_variable_set("@miniprofiler_sql_id", record) if result
57
57
 
58
58
  result
@@ -66,7 +66,7 @@ class PG::Connection
66
66
  elapsed_time = SqlPatches.elapsed_time(start)
67
67
  mapped = args[0]
68
68
  mapped = @prepare_map[mapped] || args[0] if @prepare_map
69
- record = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time)
69
+ record = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time, get_binds(mapped, args[1]))
70
70
  result.instance_variable_set("@miniprofiler_sql_id", record) if result
71
71
 
72
72
  result
@@ -80,23 +80,48 @@ class PG::Connection
80
80
  elapsed_time = SqlPatches.elapsed_time(start)
81
81
  mapped = args[0]
82
82
  mapped = @prepare_map[mapped] || args[0] if @prepare_map
83
- record = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time)
83
+ record = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time, get_binds(mapped, args[1]))
84
84
  result.instance_variable_set("@miniprofiler_sql_id", record) if result
85
85
 
86
86
  result
87
87
  end
88
88
 
89
89
  def async_exec(*args,&blk)
90
- return exec_without_profiling(*args,&blk) unless SqlPatches.should_measure?
90
+ return async_exec_without_profiling(*args,&blk) unless SqlPatches.should_measure?
91
91
 
92
92
  start = Time.now
93
93
  result = exec_without_profiling(*args,&blk)
94
94
  elapsed_time = SqlPatches.elapsed_time(start)
95
- record = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)
95
+ record = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time, get_binds(*args))
96
96
  result.instance_variable_set("@miniprofiler_sql_id", record) if result
97
97
 
98
98
  result
99
99
  end
100
100
 
101
+ def get_binds(*args)
102
+ params = args[1]
103
+ return if params.nil? || params.empty?
104
+
105
+ sql = args[0]
106
+
107
+ hh = {}
108
+ arr = nil
109
+
110
+ if sql.match(/\(\$\d/)
111
+ arr = sql.match(/\((\"\w+\",?\s?)+\)/).to_s.gsub!(/[",()]/, '').split #regular selects list of names from sql query, for ex. ("name1", "name2", "name3")
112
+ end
113
+
114
+ params.each_index do |i|
115
+ if arr
116
+ hh[arr[i]]=params[i]
117
+ else
118
+ var = sql.match(/[^\s\.]+\s?=?\s\$#{i+1}/).to_s.split[0] #regular selects param name from sql query, like for ex. "name1" = $1
119
+ var.gsub!(/["]/, '') if var
120
+ hh[var]=args[1][i]
121
+ end
122
+ end
123
+ return hh
124
+ end
125
+
101
126
  alias_method :query, :exec
102
127
  end
@@ -21,14 +21,13 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency 'rack', '>= 1.2.0'
22
22
  s.required_ruby_version = '>= 1.9.3'
23
23
 
24
- s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rake', '< 11'
25
25
  s.add_development_dependency 'rack-test'
26
26
  s.add_development_dependency 'activerecord', '~> 3.0'
27
27
  s.add_development_dependency 'dalli'
28
28
  s.add_development_dependency 'rspec', '~> 2.14.1'
29
29
  s.add_development_dependency 'redis'
30
- s.add_development_dependency 'therubyracer'
31
- s.add_development_dependency 'less'
30
+ s.add_development_dependency 'sass'
32
31
  s.add_development_dependency 'flamegraph'
33
32
 
34
33
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mini-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-08 00:00:00.000000000 Z
13
+ date: 2017-05-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -30,16 +30,16 @@ dependencies:
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - "<"
34
34
  - !ruby/object:Gem::Version
35
- version: '0'
35
+ version: '11'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '0'
42
+ version: '11'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rack-test
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -111,21 +111,7 @@ dependencies:
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
- name: therubyracer
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: less
114
+ name: sass
129
115
  requirement: !ruby/object:Gem::Requirement
130
116
  requirements:
131
117
  - - ">="
@@ -165,7 +151,7 @@ files:
165
151
  - README.md
166
152
  - lib/html/includes.css
167
153
  - lib/html/includes.js
168
- - lib/html/includes.less
154
+ - lib/html/includes.scss
169
155
  - lib/html/includes.tmpl
170
156
  - lib/html/jquery.1.7.1.js
171
157
  - lib/html/jquery.tmpl.js