rorvswild 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rorvswild/version.rb +1 -1
- data/lib/rorvswild.rb +17 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba08aa966ce2e82a89df73629d47a656d7616b84
|
4
|
+
data.tar.gz: 669ffa2a6ba1e8ed508e9ad50b395bedaec0caf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4d2da8c004d341bc9cd89aedefa78f18126d7da392745a91abd80cf87f81f2c4e73a3a64db0fc775a7cd53dc02ff7aeb706f776d1f45e6c0b146d985eeb0d6
|
7
|
+
data.tar.gz: 5945c84419fa4691d5eaeb619429b42415b32b065a62179cf50df9b2c453f6c30a52947847c9417b8d028ece5a00899c0fe5ca0bff5adc8179311e95ae94cca5
|
data/lib/rorvswild/version.rb
CHANGED
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
|
-
|
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, :
|
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
|
-
@
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2014-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|