rorvswild 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 232fd31fbdd8f8aa04082081440dab07b08476e0
4
- data.tar.gz: c2159c0e883a30214d2bb6b2230a4a1401269862
3
+ metadata.gz: 2090ba967a7c985f4403ac9e01fc364886120dd9
4
+ data.tar.gz: 6251252d0727624d67fecb7a680786baac12b89b
5
5
  SHA512:
6
- metadata.gz: 701d9293224c6ab52761adfb3af3a6b7985fc1ffe1c2675bbf80faeb2f820254e97fe151b124a79b50a08541c4176b250d71a5012766c0a3a1791952e0bc382b
7
- data.tar.gz: 5f6d5fb467f80b56fe300967fa8a40bce38cef2d057f812ee767c2825d42cde2fbc5c0a6ed645ee8810621cc4d8f9c25ca1a3212c7d7847cc014bbb72406252d
6
+ metadata.gz: 711ed99628c2daeddb99b7ca068401e1d266ab655977e39f3f79b6ca9af6e6aa6b8b051addc4e3dcf4eba0c1e6d2a002541bb332422b4102f1056b86d52343c0
7
+ data.tar.gz: 269fb5c4c938c7b891d4fb1e4f7c8515f137c3797c1fb83b2c15f981ab68f3f9fb44912ca86eb0f9035dbe6a76be634eb1de6fb5a8d50734236862734b37b0ab
@@ -100,7 +100,7 @@ module RorVsWild
100
100
  end
101
101
 
102
102
  def before_http_request(name, start, finish, id, payload)
103
- request.merge!(controller: payload[:controller], action: payload[:action], path: payload[:path])
103
+ request.merge!(controller: payload[:controller], action: payload[:action], path: payload[:path], queries: [], views: {})
104
104
  end
105
105
 
106
106
  def after_http_request(name, start, finish, id, payload)
@@ -118,7 +118,7 @@ module RorVsWild
118
118
  file, line, method = extract_most_relevant_location(caller)
119
119
  runtime, sql = compute_duration(start, finish), payload[:sql]
120
120
  plan = runtime >= explain_sql_threshold ? explain(payload[:sql], payload[:binds]) : nil
121
- push_query(file: file, line: line, method: method, sql: sql, plan: plan, runtime: runtime, times: 1)
121
+ push_query(file: file, line: line, method: method, sql: sql, plan: plan, runtime: runtime)
122
122
  rescue => exception
123
123
  log_error(exception)
124
124
  end
@@ -160,10 +160,11 @@ module RorVsWild
160
160
 
161
161
  def measure_block(name, &block)
162
162
  job[:name] = name
163
+ job[:queries] = []
163
164
  started_at = Time.now
164
165
  cpu_time_offset = cpu_time
165
166
  block.call
166
- rescue => exception
167
+ rescue Exception => exception
167
168
  job[:error] = exception_to_hash(exception)
168
169
  raise
169
170
  ensure
@@ -175,7 +176,7 @@ module RorVsWild
175
176
  def catch_error(extra_details = nil, &block)
176
177
  begin
177
178
  block.call
178
- rescue => exception
179
+ rescue Exception => exception
179
180
  record_error(exception, extra_details)
180
181
  exception
181
182
  end
@@ -197,11 +198,11 @@ module RorVsWild
197
198
  private
198
199
 
199
200
  def queries
200
- data[:queries] ||= []
201
+ data[:queries]
201
202
  end
202
203
 
203
204
  def views
204
- data[:views] ||= {}
205
+ data[:views]
205
206
  end
206
207
 
207
208
  def job
@@ -222,10 +223,16 @@ module RorVsWild
222
223
 
223
224
  def push_query(query)
224
225
  if hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] }
226
+ if query[:runtime] > hash[:max_runtime]
227
+ hash[:max_runtime] = query[:runtime]
228
+ hash[:plan] = query[:plan]
229
+ hash[:sql] = query[:sql]
230
+ end
225
231
  hash[:runtime] += query[:runtime]
226
- hash[:plan] = query[:plan]
227
232
  hash[:times] += 1
228
233
  else
234
+ query[:times] = 1
235
+ query[:max_runtime] = query[:runtime]
229
236
  queries << query
230
237
  end
231
238
  end
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.3.1".freeze
3
3
  end
@@ -79,6 +79,14 @@ class RorVsWildTest < MiniTest::Unit::TestCase
79
79
  assert_equal(["/app/models/user.rb", "3", "method3"], client.send(:extract_most_relevant_location, callstack))
80
80
  end
81
81
 
82
+ def test_push_query
83
+ client = initialize_client
84
+ client.send(:data)[:queries] = []
85
+ client.send(:push_query, {file: "file", line: 123, sql: "SELECT 1", runtime: 10})
86
+ client.send(:push_query, {file: "file", line: 123, sql: "SELECT 2", runtime: 11})
87
+ assert_equal([{file: "file", line: 123, sql: "SELECT 2", runtime: 21, max_runtime: 11, times: 2, plan: nil,}], client.send(:queries))
88
+ end
89
+
82
90
  private
83
91
 
84
92
  def client
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler