bulletmark_repairer 0.1.0 → 0.1.2
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/.rubocop.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/lib/bulletmark_repairer/{bulletmark_repairer.rb → application_associations.rb} +0 -12
- data/lib/bulletmark_repairer/associations_builder.rb +17 -10
- data/lib/bulletmark_repairer/corrector.rb +1 -1
- data/lib/bulletmark_repairer/markers.rb +2 -2
- data/lib/bulletmark_repairer/patcher.rb +3 -3
- data/lib/bulletmark_repairer/rack.rb +1 -2
- data/lib/bulletmark_repairer/version.rb +1 -1
- data/lib/bulletmark_repairer.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533eed3a74c78c89236e5c1355f588814c6a4017cf79af12f0a0e23fe030fcde
|
4
|
+
data.tar.gz: bf8a718e822ba241ab3299f675db3809870d955257bc5279644285373a619141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a33cc9ba73a76ebca97b8293677d8498761a07c2a6680e5182a65b2d8f7cb6237196506aedee63ed4f798168beb4161072ee5e62cbcee9506c4040e4584a508f
|
7
|
+
data.tar.gz: 2fb1af553ee13ca638023120306f6284b4d04ae567171616cee658ee5277f1bb33a589d769d7625ad0d6b445d06664a068dc49db479e8ac91934d36aef3553d6
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.1.2] - 2023-10-16
|
2
|
+
|
3
|
+
- Reduce dependencies [#1](https://github.com/makicamel/bulletmark_repairer/pull/1) [@tricknotes]()
|
4
|
+
- Stop using class instance variables for thread safe [024f6c5](https://github.com/makicamel/bulletmark_repairer/commit/024f6c53f82b182a998c1e43de48d8c6c9ce5bf3)
|
5
|
+
|
6
|
+
## [0.1.1] - 2023-10-11
|
7
|
+
|
8
|
+
- Support Ruby 3.0 [dbdf27c](https://github.com/makicamel/bulletmark_repairer/commit/dbdf27c6c9a7259ad9474153d2394da5bac45b43)
|
9
|
+
|
1
10
|
## [0.1.0] - 2023-10-10
|
2
11
|
|
3
12
|
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ BulletmarkRepairer is an auto corrector for N+1 queries detected at runtime on R
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'bulletmark_repairer', group
|
10
|
+
gem 'bulletmark_repairer', group: %w(development test)
|
11
11
|
```
|
12
12
|
|
13
13
|
## Usage
|
@@ -1,18 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module BulletmarkRepairer
|
4
|
-
def self.associations
|
5
|
-
@associations ||= ApplicationAssociations.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.key(target_klass_name, base_klass_name, candidates)
|
9
|
-
associations.key(target_klass_name, base_klass_name, candidates)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.reset_associations
|
13
|
-
@associations = nil
|
14
|
-
end
|
15
|
-
|
16
4
|
class ApplicationAssociations
|
17
5
|
def key(target_klass_name, base_klass_name, candidates)
|
18
6
|
key = target_klass_name.underscore
|
@@ -10,13 +10,19 @@ module BulletmarkRepairer
|
|
10
10
|
if associations[marker.index]
|
11
11
|
associations[marker.index].add(marker)
|
12
12
|
else
|
13
|
-
associations[marker.index] = Associations.new(marker)
|
13
|
+
associations[marker.index] = Associations.new(marker, @application_associations)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def associations
|
18
18
|
@associations ||= {}
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@application_associations = BulletmarkRepairer::ApplicationAssociations.new
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
class Associations
|
@@ -30,7 +36,7 @@ module BulletmarkRepairer
|
|
30
36
|
|
31
37
|
def corrector(dir)
|
32
38
|
BulletmarkRepairer::CorrectorBuilder.new(
|
33
|
-
dir
|
39
|
+
dir: dir,
|
34
40
|
marker: @marker,
|
35
41
|
associations: @associations
|
36
42
|
).execute
|
@@ -38,16 +44,17 @@ module BulletmarkRepairer
|
|
38
44
|
|
39
45
|
private
|
40
46
|
|
41
|
-
def initialize(marker)
|
47
|
+
def initialize(marker, application_associations)
|
42
48
|
@marker = marker
|
43
49
|
@associations = { base: marker.associations }
|
50
|
+
@application_associations = application_associations
|
44
51
|
end
|
45
52
|
|
46
53
|
# @return [Hash, nil]
|
47
54
|
def build_associations!(marker:, associations:, parent_keys:)
|
48
|
-
key = formed_key(marker
|
55
|
+
key = formed_key(marker: marker, associations: associations)
|
49
56
|
if key
|
50
|
-
modify_value(key
|
57
|
+
modify_value(key: key, marker: marker, parent_keys: parent_keys)
|
51
58
|
else
|
52
59
|
new_parent_keys = parent_keys
|
53
60
|
new_parent_keys.append(0) if associations.is_a?(Array)
|
@@ -56,7 +63,7 @@ module BulletmarkRepairer
|
|
56
63
|
|
57
64
|
association_values.each do |key, value|
|
58
65
|
values = value.is_a?(Array) ? value : [value]
|
59
|
-
build_associations!(marker
|
66
|
+
build_associations!(marker: marker, associations: { key => values }, parent_keys: new_parent_keys)
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
@@ -66,12 +73,12 @@ module BulletmarkRepairer
|
|
66
73
|
def formed_key(marker:, associations:)
|
67
74
|
case associations
|
68
75
|
when Hash
|
69
|
-
|
70
|
-
|
76
|
+
@application_associations.key(marker.base_class, @marker.base_class, associations.keys) ||
|
77
|
+
@application_associations.key(marker.base_class, @marker.base_class, associations.values.flatten)
|
71
78
|
when Array
|
72
|
-
|
79
|
+
@application_associations.key(marker.base_class, @marker.base_class, associations)
|
73
80
|
else # Symbol, String
|
74
|
-
|
81
|
+
@application_associations.key(marker.base_class, @marker.base_class, [associations])
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
@@ -42,7 +42,7 @@ class Corrector < Parser::TreeRewriter
|
|
42
42
|
insert_after node.children.last.location.expression, ".includes(#{associations})"
|
43
43
|
@patched = true
|
44
44
|
else
|
45
|
-
node.children.each { |child_node| insert_includes_for_vasgn(node: child_node, type:) }
|
45
|
+
node.children.each { |child_node| insert_includes_for_vasgn(node: child_node, type: type) }
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -5,9 +5,9 @@ require 'securerandom'
|
|
5
5
|
require 'parser/runner/ruby_rewrite'
|
6
6
|
|
7
7
|
module BulletmarkRepairer
|
8
|
-
class
|
8
|
+
class Patcher
|
9
9
|
def self.execute(notifications:, controller:, action:)
|
10
|
-
new(notifications
|
10
|
+
new(notifications: notifications, controller: controller, action: action).execute
|
11
11
|
end
|
12
12
|
|
13
13
|
def execute
|
@@ -25,7 +25,7 @@ module BulletmarkRepairer
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def initialize(notifications:, controller:, action:)
|
28
|
-
@markers = Markers.new(notifications, controller
|
28
|
+
@markers = Markers.new(notifications, controller: controller, action: action)
|
29
29
|
@associations_builder = BulletmarkRepairer::AssociationsBuilder.new
|
30
30
|
end
|
31
31
|
end
|
@@ -7,12 +7,11 @@ module BulletmarkRepairer
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
10
|
-
BulletmarkRepairer.reset_associations
|
11
10
|
@app.call(env)
|
12
11
|
ensure
|
13
12
|
begin
|
14
13
|
if Thread.current[:bullet_notification_collector].notifications_present?
|
15
|
-
BulletmarkRepairer::
|
14
|
+
BulletmarkRepairer::Patcher.execute(
|
16
15
|
notifications: Thread.current[:bullet_notification_collector],
|
17
16
|
controller: env['action_dispatch.request.parameters']['controller'],
|
18
17
|
action: env['action_dispatch.request.parameters']['action']
|
data/lib/bulletmark_repairer.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'bulletmark_repairer/version'
|
4
4
|
require 'bulletmark_repairer/railtie' if ENV['REPAIR']
|
5
|
-
require 'bulletmark_repairer/
|
5
|
+
require 'bulletmark_repairer/application_associations'
|
6
6
|
require 'bulletmark_repairer/associations_builder'
|
7
7
|
require 'bulletmark_repairer/configuration'
|
8
8
|
require 'bulletmark_repairer/corrector_builder'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulletmark_repairer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makicamel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bullet
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: railties
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -68,8 +82,8 @@ files:
|
|
68
82
|
- README.md
|
69
83
|
- Rakefile
|
70
84
|
- lib/bulletmark_repairer.rb
|
85
|
+
- lib/bulletmark_repairer/application_associations.rb
|
71
86
|
- lib/bulletmark_repairer/associations_builder.rb
|
72
|
-
- lib/bulletmark_repairer/bulletmark_repairer.rb
|
73
87
|
- lib/bulletmark_repairer/configuration.rb
|
74
88
|
- lib/bulletmark_repairer/controller_corrector.rb
|
75
89
|
- lib/bulletmark_repairer/corrector.rb
|
@@ -96,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
110
|
requirements:
|
97
111
|
- - ">="
|
98
112
|
- !ruby/object:Gem::Version
|
99
|
-
version: 2.
|
113
|
+
version: 2.7.0
|
100
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
116
|
- - ">="
|