prosopite 1.1.4 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df639c665fefc84471086093056a2588fa173b81c66ac43e332fba52ba536408
4
- data.tar.gz: f2fee55c16bf971f4cbba8d6b522ed097f807590024d5ec386ab8fc8f5b7b984
3
+ metadata.gz: 708963d4cc79982fc4345088cf7a60449ee2964f0065cc2adadccd41c804dc54
4
+ data.tar.gz: 9f7e85e4a52286339b16399125be61d3c91815b01d036d7512b224eec1cd8c9d
5
5
  SHA512:
6
- metadata.gz: d57e66ffe211db8c38a7188e23bc5d82aa1f30b78e0ae1564831a8fe51f85dd7f9a0a8f1c09d619d2c8754bd2dde93d6b9b1bdc95399aa215daee98a0be697f0
7
- data.tar.gz: 4a621d14b33c5943038fcc401b2d8caaa49767ffa4b3c3de5df2316dc452ae80c106c4d1150718d5318a8ee9e866903fc4b7767a32f2d288d62e35485ede182d
6
+ metadata.gz: d35c2ca3bd71b1bdc1f3ad00cf81a570b86648ac8b939220804f8538bd916cda82f4899e7ba9d72845df0a3d334c22be934f0688b15e03b496b4169f49d46d6d
7
+ data.tar.gz: b27b3c3babb72f29882e024db65303cf35243da04af0c89d093519d9f35f00aebfd047f13c63f00bfaf67c51ab18c9cbe65d73a589df650c311153a2c0a99954
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosopite (1.1.4)
4
+ prosopite (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -115,6 +115,7 @@ Or install it yourself as:
115
115
 
116
116
  The preferred type of notifications can be configured with:
117
117
 
118
+ * `Prosopite.min_n_queries`: Minimum number of N queries to report per N+1 case. Defaults to 2.
118
119
  * `Prosopite.raise = true`: Raise warnings as exceptions
119
120
  * `Prosopite.rails_logger = true`: Send warnings to the Rails log
120
121
  * `Prosopite.prosopite_logger = true`: Send warnings to `log/prosopite.log`
@@ -269,6 +270,8 @@ end
269
270
  Prosopite.finish
270
271
  ```
271
272
 
273
+ Pauses can be ignored with `Prosopite.ignore_pauses = true` in case you want to remember their N+1 queries.
274
+
272
275
  An example of when you might use this is if you are [testing Active Jobs inline](https://guides.rubyonrails.org/testing.html#testing-jobs),
273
276
  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.
274
277
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "1.1.4"
4
+ VERSION = "1.2.1"
5
5
  end
data/lib/prosopite.rb CHANGED
@@ -10,7 +10,9 @@ module Prosopite
10
10
  :prosopite_logger,
11
11
  :custom_logger,
12
12
  :allow_stack_paths,
13
- :ignore_queries
13
+ :ignore_queries,
14
+ :ignore_pauses,
15
+ :min_n_queries
14
16
 
15
17
  def allow_list=(value)
16
18
  puts "Prosopite.allow_list= is deprecated. Use Prosopite.allow_stack_paths= instead."
@@ -29,6 +31,8 @@ module Prosopite
29
31
  tc[:prosopite_query_caller] = {}
30
32
 
31
33
  @allow_stack_paths ||= []
34
+ @ignore_pauses ||= false
35
+ @min_n_queries ||= 2
32
36
 
33
37
  tc[:prosopite_scan] = true
34
38
 
@@ -48,6 +52,10 @@ module Prosopite
48
52
  end
49
53
 
50
54
  def pause
55
+ if @ignore_pauses
56
+ return block_given? ? yield : nil
57
+ end
58
+
51
59
  if block_given?
52
60
  begin
53
61
  previous = tc[:prosopite_scan]
@@ -83,8 +91,8 @@ module Prosopite
83
91
  tc[:prosopite_notifications] = {}
84
92
 
85
93
  tc[:prosopite_query_counter].each do |location_key, count|
86
- if count > 1
87
- fingerprints = tc[:prosopite_query_holder][location_key].map do |q|
94
+ if count >= @min_n_queries
95
+ fingerprints = tc[:prosopite_query_holder][location_key].group_by do |q|
88
96
  begin
89
97
  fingerprint(q)
90
98
  rescue
@@ -92,15 +100,18 @@ module Prosopite
92
100
  end
93
101
  end
94
102
 
95
- next unless fingerprints.uniq.size == 1
103
+ queries = fingerprints.values.select { |q| q.size >= @min_n_queries }
104
+
105
+ next unless queries.any?
96
106
 
97
107
  kaller = tc[:prosopite_query_caller][location_key]
98
108
  allow_list = (@allow_stack_paths + DEFAULT_ALLOW_LIST)
99
109
  is_allowed = kaller.any? { |f| allow_list.any? { |s| f.match?(s) } }
100
110
 
101
111
  unless is_allowed
102
- queries = tc[:prosopite_query_holder][location_key]
103
- tc[:prosopite_notifications][queries] = kaller
112
+ queries.each do |q|
113
+ tc[:prosopite_notifications][q] = kaller
114
+ end
104
115
  end
105
116
  end
106
117
  end
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.1.4
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mpampis Kostas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry