prosopite 1.0.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -4
- data/lib/prosopite/version.rb +1 -1
- data/lib/prosopite.rb +17 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80a80552bf3cde44c5364bb227937e151b53926b011be7179b48c6cc71696c0
|
4
|
+
data.tar.gz: 177fdf84e5340fe4d3435e93aeadbf44229678fe3316713ce3771793bbe69935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23f05d4f8e76c8f99bd59e963a61952b245f72b44148fb8f3ec8a85a49f8fbceec17517328dc3409d1d3987a07f57de5e278365be3fb4ff526a32c8e59c0163
|
7
|
+
data.tar.gz: 586d95eae04d1a25c61c42760a11a870dfdab79cd81339aff4b2220f347aa6dbab33c4fda2a0cb023a72bf97058a3017a32a56fb0f7e787ddad38c88f9eaf364
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -127,11 +127,12 @@ Prosopite auto-detection can be enabled on all controllers:
|
|
127
127
|
```ruby
|
128
128
|
class ApplicationController < ActionController::Base
|
129
129
|
unless Rails.env.production?
|
130
|
-
|
130
|
+
around_action :n_plus_one_detection
|
131
|
+
|
132
|
+
def n_plus_one_detection
|
131
133
|
Prosopite.scan
|
132
|
-
|
133
|
-
|
134
|
-
after_action do
|
134
|
+
yield
|
135
|
+
ensure
|
135
136
|
Prosopite.finish
|
136
137
|
end
|
137
138
|
end
|
@@ -202,6 +203,23 @@ Prosopite.scan do
|
|
202
203
|
end
|
203
204
|
```
|
204
205
|
|
206
|
+
## Pausing and resuming scans
|
207
|
+
|
208
|
+
Scans can be paused:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Prosopite.scan
|
212
|
+
# <code to scan>
|
213
|
+
Prosopite.pause
|
214
|
+
# <code that has n+1s>
|
215
|
+
Prosopite.resume
|
216
|
+
# <code to scan>
|
217
|
+
Prosopite.finish
|
218
|
+
```
|
219
|
+
|
220
|
+
An example of when you might use this is if you are [testing Active Jobs inline](https://guides.rubyonrails.org/testing.html#testing-jobs),
|
221
|
+
and don't want to run Prosopite on background job code, just foreground app code. In that case you could write an [Active Job callback](https://edgeguides.rubyonrails.org/active_job_basics.html#callbacks) that pauses the scan while the job is running.
|
222
|
+
|
205
223
|
## Contributing
|
206
224
|
|
207
225
|
Bug reports and pull requests are welcome on GitHub at https://github.com/charkost/prosopite.
|
data/lib/prosopite/version.rb
CHANGED
data/lib/prosopite.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
|
2
2
|
module Prosopite
|
3
|
+
DEFAULT_ALLOW_LIST = %w(active_record/associations/preloader active_record/validations/uniqueness)
|
4
|
+
|
3
5
|
class NPlusOneQueriesError < StandardError; end
|
4
6
|
class << self
|
5
7
|
attr_writer :raise,
|
@@ -36,6 +38,14 @@ module Prosopite
|
|
36
38
|
Thread.current
|
37
39
|
end
|
38
40
|
|
41
|
+
def pause
|
42
|
+
tc[:prosopite_scan] = false
|
43
|
+
end
|
44
|
+
|
45
|
+
def resume
|
46
|
+
tc[:prosopite_scan] = true
|
47
|
+
end
|
48
|
+
|
39
49
|
def scan?
|
40
50
|
tc[:prosopite_scan]
|
41
51
|
end
|
@@ -62,14 +72,14 @@ module Prosopite
|
|
62
72
|
end
|
63
73
|
end
|
64
74
|
|
75
|
+
next unless fingerprints.uniq.size == 1
|
76
|
+
|
65
77
|
kaller = tc[:prosopite_query_caller][location_key]
|
66
78
|
|
67
|
-
|
79
|
+
is_allowed = kaller.any? { |f| (@allow_list + DEFAULT_ALLOW_LIST).any? { |s| f.include?(s) } }
|
80
|
+
unless is_allowed
|
68
81
|
queries = tc[:prosopite_query_holder][location_key]
|
69
|
-
|
70
|
-
unless kaller.any? { |f| f.include?('active_record/validations/uniqueness') }
|
71
|
-
tc[:prosopite_notifications][queries] = kaller
|
72
|
-
end
|
82
|
+
tc[:prosopite_notifications][queries] = kaller
|
73
83
|
end
|
74
84
|
end
|
75
85
|
end
|
@@ -175,9 +185,9 @@ module Prosopite
|
|
175
185
|
return if @subscribed
|
176
186
|
|
177
187
|
ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data|
|
178
|
-
sql = data[:sql]
|
188
|
+
sql, name = data[:sql], data[:name]
|
179
189
|
|
180
|
-
if scan? && sql.include?('SELECT') && data[:cached].nil?
|
190
|
+
if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil?
|
181
191
|
location_key = Digest::SHA1.hexdigest(caller.join)
|
182
192
|
|
183
193
|
tc[:prosopite_query_counter][location_key] += 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prosopite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mpampis Kostas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|