rorvswild 0.2.3 → 0.3.0

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: f1688d79676d52dc69efdbf5cb2149f0f1e8af89
4
- data.tar.gz: 3c3428fd9bb732a4b18513206cb240e7125ad7ee
3
+ metadata.gz: 232fd31fbdd8f8aa04082081440dab07b08476e0
4
+ data.tar.gz: c2159c0e883a30214d2bb6b2230a4a1401269862
5
5
  SHA512:
6
- metadata.gz: 2320d56b3563cf5a0257117e0b2eadf1958546aef3b40c84616da98d4068dc2a2844b879396e0532f0c910f8103f058896c8d963c11abcff8a24b19d03d2fd90
7
- data.tar.gz: baffb82f1be10cf110c3d22230873af90e3bc2bc3269c04df3a1a4b896f504d062a85ff623927238f47a93f9840eb1e28ac880f470bccf68add3d8f2284bfdc3
6
+ metadata.gz: 701d9293224c6ab52761adfb3af3a6b7985fc1ffe1c2675bbf80faeb2f820254e97fe151b124a79b50a08541c4176b250d71a5012766c0a3a1791952e0bc382b
7
+ data.tar.gz: 5f6d5fb467f80b56fe300967fa8a40bce38cef2d057f812ee767c2825d42cde2fbc5c0a6ed645ee8810621cc4d8f9c25ca1a3212c7d7847cc014bbb72406252d
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -10,6 +10,19 @@ module RorVsWild
10
10
  Client.new(*args) # Compatibility with 0.0.1
11
11
  end
12
12
 
13
+ def self.detect_config_file
14
+ return if !defined?(Rails)
15
+ Rails::Railtie.initializer "rorvswild.detect_config_file" do
16
+ if !RorVsWild.default_client && (path = Rails.root.join("config/rorvswild.yml")).exist?
17
+ RorVsWild.load_config_file(path, Rails.env)
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.load_config_file(path, environment)
23
+ config = YAML.load_file(path)[environment.to_s] and Client.new(config.symbolize_keys)
24
+ end
25
+
13
26
  def self.register_default_client(client)
14
27
  @default_client = client
15
28
  end
@@ -43,16 +56,14 @@ module RorVsWild
43
56
  {
44
57
  api_url: "http://www.rorvswild.com/api",
45
58
  explain_sql_threshold: 500,
46
- log_sql_threshold: 100,
47
59
  }
48
60
  end
49
61
 
50
- attr_reader :api_url, :api_key, :app_id, :explain_sql_threshold, :log_sql_threshold, :app_root, :app_root_regex
62
+ attr_reader :api_url, :api_key, :app_id, :explain_sql_threshold, :app_root, :app_root_regex
51
63
 
52
64
  def initialize(config)
53
65
  config = self.class.default_config.merge(config)
54
66
  @explain_sql_threshold = config[:explain_sql_threshold]
55
- @log_sql_threshold = config[:log_sql_threshold]
56
67
  @app_root = config[:app_root]
57
68
  @api_url = config[:api_url]
58
69
  @api_key = config[:api_key]
@@ -103,13 +114,10 @@ module RorVsWild
103
114
  end
104
115
 
105
116
  def after_sql_query(name, start, finish, id, payload)
106
- return if !queries || payload[:name] == "EXPLAIN".freeze
107
- runtime, sql, plan = compute_duration(start, finish), nil, nil
117
+ return if !queries || payload[:name] == "EXPLAIN".freeze || payload[:name] == "SCHEMA".freeze
108
118
  file, line, method = extract_most_relevant_location(caller)
109
- # I can't figure out the exact location which triggered the query, so at least the SQL is logged.
110
- sql, file, line, method = payload[:sql], "Unknow", 0, "Unknow" if !file
111
- sql = payload[:sql] if runtime >= log_sql_threshold
112
- plan = explain(payload[:sql], payload[:binds]) if runtime >= explain_sql_threshold
119
+ runtime, sql = compute_duration(start, finish), payload[:sql]
120
+ plan = runtime >= explain_sql_threshold ? explain(payload[:sql], payload[:binds]) : nil
113
121
  push_query(file: file, line: line, method: method, sql: sql, plan: plan, runtime: runtime, times: 1)
114
122
  rescue => exception
115
123
  log_error(exception)
@@ -213,15 +221,12 @@ module RorVsWild
213
221
  end
214
222
 
215
223
  def push_query(query)
216
- if query[:sql] || query[:plan]
217
- queries << query
224
+ if hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] }
225
+ hash[:runtime] += query[:runtime]
226
+ hash[:plan] = query[:plan]
227
+ hash[:times] += 1
218
228
  else
219
- if hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] }
220
- hash[:runtime] += query[:runtime]
221
- hash[:times] += 1
222
- else
223
- queries << query
224
- end
229
+ queries << query
225
230
  end
226
231
  end
227
232
 
@@ -320,8 +325,8 @@ module RorVsWild
320
325
  end
321
326
 
322
327
  def log_error(exception)
323
- logger.puts("[RorVsWild] " + exception.inspect)
324
- logger.puts("[RorVsWild] " + exception.backtrace.join("\n[RorVsWild] "))
328
+ @logger.error("[RorVsWild] " + exception.inspect)
329
+ @logger.error("[RorVsWild] " + exception.backtrace.join("\n[RorVsWild] "))
325
330
  end
326
331
  end
327
332
 
@@ -339,3 +344,5 @@ module RorVsWild
339
344
  end
340
345
  end
341
346
  end
347
+
348
+ RorVsWild.detect_config_file
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.2.3
4
+ version: 0.3.0
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-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler