rorvswild 0.0.3 → 0.0.4

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: f54f409b8f0d1dedb0891da5a680d7a701a67a2d
4
- data.tar.gz: bb647ca3ce47cc27fd6279dd25fbabae7d48ab15
3
+ metadata.gz: ba08aa966ce2e82a89df73629d47a656d7616b84
4
+ data.tar.gz: 669ffa2a6ba1e8ed508e9ad50b395bedaec0caf2
5
5
  SHA512:
6
- metadata.gz: af4176a3d8b8e48db393dfb0001c616184a98ca885163fb566f98bd089deac147eea471a372d0821d4120153088d0ec83af23007d69aad557e2f9d1d6b9ea185
7
- data.tar.gz: 3b35e6030188581d2a8e239aa7163742665fd6401f38788f8046e62668fd79ba13858466254a22a2a32f631519f03562b721dcd92c52bb24daaf839f7b03066f
6
+ metadata.gz: 4e4d2da8c004d341bc9cd89aedefa78f18126d7da392745a91abd80cf87f81f2c4e73a3a64db0fc775a7cd53dc02ff7aeb706f776d1f45e6c0b146d985eeb0d6
7
+ data.tar.gz: 5945c84419fa4691d5eaeb619429b42415b32b065a62179cf50df9b2c453f6c30a52947847c9417b8d028ece5a00899c0fe5ca0bff5adc8179311e95ae94cca5
@@ -1,3 +1,3 @@
1
1
  class Rorvswild
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -9,15 +9,17 @@ module RorVsWild
9
9
  def self.default_config
10
10
  {
11
11
  api_url: "http://www.rorvswild.com/api",
12
- sql_threshold: 500
12
+ explain_sql_threshold: 500,
13
+ log_sql_threshold: 100,
13
14
  }
14
15
  end
15
16
 
16
- attr_reader :api_url, :api_key, :app_id, :sql_threshold, :error, :request
17
+ attr_reader :api_url, :api_key, :app_id, :error, :request, :explain_sql_threshold, :log_sql_threshold
17
18
 
18
19
  def initialize(config)
19
20
  config = self.class.default_config.merge(config)
20
- @sql_threshold = config[:sql_threshold]
21
+ @explain_sql_threshold = config[:explain_sql_threshold]
22
+ @log_sql_threshold = config[:log_sql_threshold]
21
23
  @api_url = config[:api_url]
22
24
  @api_key = config[:api_key]
23
25
  @app_id = config[:app_id]
@@ -53,14 +55,11 @@ module RorVsWild
53
55
  return if !queries || payload[:name] == "EXPLAIN".freeze
54
56
  runtime, sql, plan = compute_duration(start, finish), nil, nil
55
57
  file, line, method = extract_file_and_line_from_call_stack(caller)
56
-
57
- if !file # I have no idea of the origin of the query, so at least we log the SQL.
58
- file, line, method = ["Unknow", 0, "Unknow"]
59
- sql = payload[:sql]
60
- end
61
-
62
- plan = explain(sql = payload[:sql], payload[:binds]) if runtime > sql_threshold
63
- queries << {file: file, line: line, sql: sql, plan: plan, runtime: runtime}
58
+ # I can't figure out the exact location which triggered the query, so at least the SQL is logged.
59
+ sql, file, line, method = payload[:sql], "Unknow", 0, "Unknow" if !file
60
+ sql = payload[:sql] if runtime >= log_sql_threshold
61
+ plan = explain(payload[:sql], payload[:binds]) if runtime >= explain_sql_threshold
62
+ queries << {file: file, line: line, method: method, sql: sql, plan: plan, runtime: runtime}
64
63
  rescue => exception
65
64
  log_error(exception)
66
65
  end
@@ -116,15 +115,18 @@ module RorVsWild
116
115
  end
117
116
 
118
117
  def extract_file_and_line_from_call_stack(stack)
119
- location = stack.find { |str| str.include?(Rails.root.to_s) } ||
120
- stack.find { |str| !str.include?("/active_support/notifications/") } # Origin of the call comes from a gem probably
121
- return unless location # Ok I have no idea
118
+ return unless location = stack.find { |str| str.include?(Rails.root.to_s) }
122
119
  file, line, method = location.split(":")
120
+ method = cleanup_method_name(method)
123
121
  file.sub!(Rails.root.to_s, "")
122
+ [file, line, method]
123
+ end
124
+
125
+ def cleanup_method_name(method)
124
126
  method.sub!("block in ", "")
125
127
  method.sub!("in `", "")
126
128
  method.sub!("'", "")
127
- [file, line, method]
129
+ method.index("_app_views_") == 0 ? nil : method
128
130
  end
129
131
 
130
132
  def compute_duration(start, finish)
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler