spring_onion 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +3 -3
- data/lib/spring_onion.rb +1 -0
- data/lib/spring_onion/config.rb +14 -11
- data/lib/spring_onion/explainer.rb +17 -8
- data/lib/spring_onion/version.rb +1 -1
- data/spring_onion.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f81f2b07f2a586b8e02444106908d6d8eb8631d772db5bff80dd0fa6ee72b550
|
4
|
+
data.tar.gz: 0e23da7945c119c5c5dcf90f2ead4985647536d0c7f3cb091b47e8f2c94ae168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 115c03712806b8b97d9ff1e65f512db06e8ebc9f4e555b743d97c57b9159c58dc4f43410b7fb73db178a584425e22b403f6005ed3be6cb9a01c57b3295c686e3
|
7
|
+
data.tar.gz: 4aa1951677c97b2fa2b45e2eeb3d49b51543e1632537c316a9d73d775b73b95472ced9074e06adc32d4c523bef5f069b9c4826c1f4bdf0a1e638e61d458dc2e1
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spring_onion (0.
|
4
|
+
spring_onion (0.2.1)
|
5
5
|
activerecord
|
6
|
+
coderay
|
6
7
|
mysql2
|
7
8
|
|
8
9
|
GEM
|
@@ -24,6 +25,7 @@ GEM
|
|
24
25
|
rake
|
25
26
|
thor (>= 0.14.0)
|
26
27
|
ast (2.4.1)
|
28
|
+
coderay (1.1.3)
|
27
29
|
concurrent-ruby (1.1.6)
|
28
30
|
diff-lcs (1.4.4)
|
29
31
|
i18n (1.8.3)
|
data/README.md
CHANGED
@@ -39,8 +39,8 @@ SpringOnion.source_filter_re = //
|
|
39
39
|
|
40
40
|
class Employee < ActiveRecord::Base; end
|
41
41
|
|
42
|
-
Employee.all.to_a.count
|
43
|
-
#=> SpringOnion INFO 2020-07-18 01:53:27 +0900 {"sql":"SELECT `employees`.* FROM `employees`","explain":[{"line":1,"select_type":"SIMPLE","table":"employees","partitions":null,"type":"ALL","possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":298936,"filtered":100.0,"Extra":null}],"
|
42
|
+
p Employee.all.to_a.count
|
43
|
+
#=> SpringOnion INFO 2020-07-18 01:53:27 +0900 {"sql":"SELECT `employees`.* FROM `employees`","explain":[{"line":1,"select_type":"SIMPLE","table":"employees","partitions":null,"type":"ALL","possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":298936,"filtered":100.0,"Extra":null}],"warnings":{"line 1":["slow_type"]},"backtrace":["/foo/bar/zoo/baz.rb:18:in `\u003ctop (required)\u003e'"]}
|
44
44
|
#=> 300024
|
45
45
|
```
|
46
46
|
|
@@ -65,7 +65,7 @@ Employee.all.to_a.count
|
|
65
65
|
"Extra": null
|
66
66
|
}
|
67
67
|
],
|
68
|
-
"
|
68
|
+
"warnings": {
|
69
69
|
"line 1": [
|
70
70
|
"slow_type"
|
71
71
|
]
|
data/lib/spring_onion.rb
CHANGED
data/lib/spring_onion/config.rb
CHANGED
@@ -17,7 +17,7 @@ module SpringOnion
|
|
17
17
|
'Using temporary'
|
18
18
|
)
|
19
19
|
|
20
|
-
@
|
20
|
+
@warnings = {
|
21
21
|
slow_select_type: ->(exp) { SLOW_SELECT_TYPE_RE =~ exp['select_type'] },
|
22
22
|
slow_type: ->(exp) { SLOW_TYPE_RE =~ exp['type'] },
|
23
23
|
slow_possible_keys: ->(exp) { SLOW_POSSIBLE_KEYS_RE =~ exp['possible_keys'] },
|
@@ -42,22 +42,21 @@ module SpringOnion
|
|
42
42
|
@ignore_sql_filter_re !~ sql && @sql_filter_re =~ sql
|
43
43
|
end
|
44
44
|
|
45
|
-
@source_filter_re =
|
46
|
-
|
47
|
-
|
48
|
-
ary << Regexp.new(re) if re
|
49
|
-
end
|
50
|
-
)
|
45
|
+
@source_filter_re = ENV['SPRING_ONION_SOURCE_FILTER_RE'].yield_self do |re|
|
46
|
+
re ? Regexp.new(re) : %r{/app/}
|
47
|
+
end
|
51
48
|
|
52
49
|
@ignore_source_filter_re = Regexp.union(
|
53
|
-
[RbConfig::TOPDIR, *Gem.path].tap do |ary|
|
50
|
+
[RbConfig::TOPDIR, *Gem.path, '/.rbenv/versions/'].tap do |ary|
|
54
51
|
re = ENV['SPRING_ONION_IGNORE_SOURCE_FILTER_RE']
|
55
52
|
ary << Regexp.new(re) if re
|
56
53
|
end
|
57
54
|
)
|
58
55
|
|
59
56
|
@source_filter = lambda do |backtrace_lines|
|
60
|
-
backtrace_lines.grep_v(@ignore_source_filter_re)
|
57
|
+
backtrace_lines = backtrace_lines.grep_v(@ignore_source_filter_re)
|
58
|
+
idx = backtrace_lines.index { |l| @source_filter_re =~ l }
|
59
|
+
idx ? backtrace_lines.slice(idx..-1) : []
|
61
60
|
end
|
62
61
|
|
63
62
|
@logger = Logger.new($stdout).tap do |logger|
|
@@ -67,14 +66,18 @@ module SpringOnion
|
|
67
66
|
end
|
68
67
|
|
69
68
|
@trace_len = 3
|
69
|
+
@json_pretty = (/\A(1|true)\z/i =~ ENV['SPRING_ONION_JSON_PRETTY'])
|
70
|
+
@color = /\A(1|true)\z/i =~ ENV.fetch('SPRING_ONION_COLOR', $stdout.tty?.to_s)
|
70
71
|
|
71
72
|
class << self
|
72
73
|
attr_accessor :enabled,
|
73
74
|
:connection,
|
74
|
-
:
|
75
|
+
:warnings,
|
75
76
|
:sql_filter_re, :ignore_sql_filter_re, :sql_filter,
|
76
77
|
:source_filter_re, :ignore_source_filter_re, :source_filter,
|
77
78
|
:logger,
|
78
|
-
:trace_len
|
79
|
+
:trace_len,
|
80
|
+
:json_pretty,
|
81
|
+
:color
|
79
82
|
end
|
80
83
|
end
|
@@ -30,25 +30,34 @@ module SpringOnion
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def _validate(exp, sql, trace)
|
33
|
-
|
34
|
-
|
33
|
+
warnings = SpringOnion.warnings
|
34
|
+
warning_names_by_line = {}
|
35
35
|
|
36
36
|
exp.each_with_index do |row, i|
|
37
|
-
|
37
|
+
warning_names = warnings.select do |_name, validator|
|
38
38
|
validator.call(row)
|
39
39
|
end.keys
|
40
40
|
|
41
|
-
|
41
|
+
warning_names_by_line["line #{i + 1}"] = warning_names unless warning_names.empty?
|
42
42
|
end
|
43
43
|
|
44
|
-
return if
|
44
|
+
return if warning_names_by_line.empty?
|
45
45
|
|
46
|
-
|
46
|
+
h = {
|
47
47
|
sql: sql,
|
48
48
|
explain: exp.each_with_index.map { |r, i| { line: i + 1 }.merge(r) },
|
49
|
-
|
49
|
+
warnings: warning_names_by_line,
|
50
50
|
backtrace: trace.slice(0, SpringOnion.trace_len),
|
51
|
-
}
|
51
|
+
}
|
52
|
+
|
53
|
+
line = if SpringOnion.json_pretty
|
54
|
+
JSON.pretty_generate(h)
|
55
|
+
else
|
56
|
+
JSON.dump(h)
|
57
|
+
end
|
58
|
+
|
59
|
+
line = CodeRay.scan(line, :json).terminal if SpringOnion.color
|
60
|
+
SpringOnion.logger.info(line)
|
52
61
|
end
|
53
62
|
end
|
54
63
|
end
|
data/lib/spring_onion/version.rb
CHANGED
data/spring_onion.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'Log MySQL queries with EXPLAIN that may be slow.'
|
13
13
|
spec.homepage = 'https://github.com/winebarrel/spring_onion'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
16
16
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
18
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
26
|
spec.add_dependency 'activerecord'
|
27
|
+
spec.add_dependency 'coderay'
|
27
28
|
spec.add_dependency 'mysql2'
|
28
29
|
spec.add_development_dependency 'appraisal'
|
29
30
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring_onion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coderay
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: mysql2
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.
|
159
|
+
version: 2.5.0
|
146
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
162
|
- - ">="
|