prosopite 0.1.5 → 0.1.6

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: e45d47e93e239165f045462c1247f33b4dae5796e1c852fd7a2a6ade0977ef2a
4
- data.tar.gz: 25c2afb9c1340d3e16c3fcd2ba880becdfc674c54aaecba4d83566c6585998de
3
+ metadata.gz: 77a2d861398e1f7a76cc71705f68d1f7287ca1343b3bd8fcf7e909f941682125
4
+ data.tar.gz: 586d0e356edfb83152c538bc4b017d9e8009d6fcd1ba746ec2cf677a97ea7f23
5
5
  SHA512:
6
- metadata.gz: 3eb734873fc1c396b5312dc70fe91a4c10a8adb4658bce2302559e8d61db22cc6e54429806e99e3014308b1e236b69a34f75e59bd3b789f36145843390776998
7
- data.tar.gz: 626d2a7ebaf7553647672f137696adfe2aa70fe67589b7380c2366862c85022ee560dfbe2665f7580c4cd930a95d7c94e1a59557d4674c563379fef94e197846
6
+ metadata.gz: 3c4e9d238b5f10d8f57531d84024758d3a6e05b4b3cefb49317c1576a0cbcf71287bcd77050ddfc073b1f03cdb3a601bb6f33a49f4488f7ab4483f51f19e7af0
7
+ data.tar.gz: 3f22640ed22014cd38f47e770de44253314e134192745fc3abf43d14374d815d249929f4e1dd754c46318e579ee40cf1b76ba90aa7009dd18c15f42a642aa39c
data/LICENSE.txt CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright [yyyy] [name of copyright owner]
190
+ Copyright 2021 Mpampis Kostas
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -168,12 +168,12 @@ end
168
168
 
169
169
  WARNING: scan/finish should run before/after **each** test and NOT before/after the whole suite.
170
170
 
171
- ## Whitelisting
171
+ ## Allow list
172
172
 
173
173
  Ignore notifications for call stacks containing one or more substrings:
174
174
 
175
175
  ```ruby
176
- Prosopite.whitelist = ['substring_in_call_stack']
176
+ Prosopite.allow_list = ['substring_in_call_stack']
177
177
  ```
178
178
 
179
179
  ## Scanning code outside controllers or tests
data/lib/prosopite.rb CHANGED
@@ -7,42 +7,46 @@ module Prosopite
7
7
  :stderr_logger,
8
8
  :rails_logger,
9
9
  :prosopite_logger,
10
- :whitelist
10
+ :allow_list
11
11
 
12
12
  def scan
13
- @scan ||= false
13
+ tc[:prosopite_scan] ||= false
14
14
  return if scan?
15
15
 
16
16
  subscribe
17
17
 
18
- @query_counter = Hash.new(0)
19
- @query_holder = Hash.new { |h, k| h[k] = [] }
20
- @query_caller = {}
18
+ tc[:prosopite_query_counter] = Hash.new(0)
19
+ tc[:prosopite_query_holder] = Hash.new { |h, k| h[k] = [] }
20
+ tc[:prosopite_query_caller] = {}
21
21
 
22
- @whitelist ||= []
22
+ @allow_list ||= []
23
23
 
24
- @scan = true
24
+ tc[:prosopite_scan] = true
25
+ end
26
+
27
+ def tc
28
+ Thread.current
25
29
  end
26
30
 
27
31
  def scan?
28
- @scan
32
+ tc[:prosopite_scan]
29
33
  end
30
34
 
31
35
  def finish
32
36
  return unless scan?
33
37
 
34
- @scan = false
38
+ tc[:prosopite_scan] = false
35
39
 
36
40
  create_notifications
37
- send_notifications if @notifications.present?
41
+ send_notifications if tc[:prosopite_notifications].present?
38
42
  end
39
43
 
40
44
  def create_notifications
41
- @notifications = {}
45
+ tc[:prosopite_notifications] = {}
42
46
 
43
- @query_counter.each do |location_key, count|
47
+ tc[:prosopite_query_counter].each do |location_key, count|
44
48
  if count > 1
45
- fingerprints = @query_holder[location_key].map do |q|
49
+ fingerprints = tc[:prosopite_query_holder][location_key].map do |q|
46
50
  begin
47
51
  fingerprint(q)
48
52
  rescue
@@ -50,13 +54,13 @@ module Prosopite
50
54
  end
51
55
  end
52
56
 
53
- kaller = @query_caller[location_key]
57
+ kaller = tc[:prosopite_query_caller][location_key]
54
58
 
55
- if fingerprints.uniq.size == 1 && !kaller.any? { |f| @whitelist.any? { |s| f.include?(s) } }
56
- queries = @query_holder[location_key]
59
+ if fingerprints.uniq.size == 1 && !kaller.any? { |f| @allow_list.any? { |s| f.include?(s) } }
60
+ queries = tc[:prosopite_query_holder][location_key]
57
61
 
58
62
  unless kaller.any? { |f| f.include?('active_record/validations/uniqueness') }
59
- @notifications[queries] = kaller
63
+ tc[:prosopite_notifications][queries] = kaller
60
64
  end
61
65
  end
62
66
  end
@@ -126,7 +130,7 @@ module Prosopite
126
130
 
127
131
  notifications_str = ''
128
132
 
129
- @notifications.each do |queries, kaller|
133
+ tc[:prosopite_notifications].each do |queries, kaller|
130
134
  notifications_str << "N+1 queries detected:\n"
131
135
  queries.each { |q| notifications_str << " #{q}\n" }
132
136
  notifications_str << "Call stack:\n"
@@ -149,8 +153,8 @@ module Prosopite
149
153
  end
150
154
 
151
155
  def subscribe
152
- @subscribed ||= false
153
- return if @subscribed
156
+ tc[:prosopite_subscribed] ||= false
157
+ return if tc[:prosopite_subscribed]
154
158
 
155
159
  ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data|
156
160
  sql = data[:sql]
@@ -158,16 +162,16 @@ module Prosopite
158
162
  if scan? && sql.include?('SELECT') && data[:cached].nil?
159
163
  location_key = Digest::SHA1.hexdigest(caller.join)
160
164
 
161
- @query_counter[location_key] += 1
162
- @query_holder[location_key] << sql
165
+ tc[:prosopite_query_counter][location_key] += 1
166
+ tc[:prosopite_query_holder][location_key] << sql
163
167
 
164
- if @query_counter[location_key] > 1
165
- @query_caller[location_key] = caller.dup
168
+ if tc[:prosopite_query_counter][location_key] > 1
169
+ tc[:prosopite_query_caller][location_key] = caller.dup
166
170
  end
167
171
  end
168
172
  end
169
173
 
170
- @subscribed = true
174
+ tc[:prosopite_subscribed] = true
171
175
  end
172
176
  end
173
177
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  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: 0.1.5
4
+ version: 0.1.6
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-02-27 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_query