bulletmark_repairer 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: 3d44edbc5a6deb0c95e4e1ed79c2f2b1c7b283ff54e3f00d33bbf9a8b70f698e
4
- data.tar.gz: 5d3ba75ca53cd5e721f971894fc2f1001e1fd391f4daf44a53184ef861cb532b
3
+ metadata.gz: 5eabc96bcf1961f834090322c3b9a62173139f806513c5ec99d452f18a661c71
4
+ data.tar.gz: b55ab6f5adade690b6cb34ef92fc752bdfa697a3b8d7779d54150aaf4e1083bb
5
5
  SHA512:
6
- metadata.gz: 617f5750639fe286efd6fa7d0d7bb40d0be0d258ef94600717ad98f2f46c6bfad966ea651bd5b0113f3ab9b0ff4d5749a5316bc7cca7c83c7dabc781d890ac20
7
- data.tar.gz: e6698f869f1c1f50b08332c6ec3134cfd32716325c5b2607e4a7247cf5bf807ed5f39f633822288d641246167b82e1f6b6e969d24b7cde322764204823fbea24
6
+ metadata.gz: 714da7b74b7015194f965c83c1260d31b8a4f75b4f7a24b3038eac6c81ced4aa8a77a79abbe5a684a347093fbb00d0e9f1b05682729b96afe64ed2a83b110534
7
+ data.tar.gz: e48064688caaa2003d30192bfd2a76ff677fdcb4b4bb02bb8b828fece22b9fd5dab69a47aef2fb836a69e9f5b16db10d2c1faefcb9e249ba5b8a3df671310c03
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.1.6] - 2023-11-09
2
+
3
+ Fix a bug when N+1 is caused not in the request (e.g. Sidekiq) [51f051e](https://github.com/makicamel/bulletmark_repairer/commit/51f051e608b84b7da96ac879a324ed438c14eeeb)
4
+
1
5
  ## [0.1.5] - 2023-10-27
2
6
 
3
7
  Be able to patch for nested associations require `includes` though child associations are already included [d1b7445](https://github.com/makicamel/bulletmark_repairer/commit/d1b7445556c20bc037beb6a013ac70531426a7ea)
@@ -4,17 +4,17 @@ module BulletmarkRepairer
4
4
  module ActiveRecord
5
5
  module QueryMethod
6
6
  def includes(*args)
7
- Thread.current[:bulletmark_repaier_loaded_associations][model.name][:includes].add(args)
7
+ BulletmarkRepairer::Thread.add(name: model.name, method_type: :includes, args: args)
8
8
  super(args)
9
9
  end
10
10
 
11
11
  def eager_load(*args)
12
- Thread.current[:bulletmark_repaier_loaded_associations][model.name][:eager_load].add(args)
12
+ BulletmarkRepairer::Thread.add(name: model.name, method_type: :eager_load, args: args)
13
13
  super(args)
14
14
  end
15
15
 
16
16
  def preload(*args)
17
- Thread.current[:bulletmark_repaier_loaded_associations][model.name][:preload].add(args)
17
+ BulletmarkRepairer::Thread.add(name: model.name, method_type: :preload, args: args)
18
18
  super(args)
19
19
  end
20
20
  end
@@ -7,24 +7,21 @@ module BulletmarkRepairer
7
7
  end
8
8
 
9
9
  def call(env)
10
- Thread.current[:bulletmark_repaier_loaded_associations] = Hash.new do |hash, key|
11
- hash[key] = { includes: Set.new, eager_load: Set.new, preload: Set.new }
12
- end
13
10
  @app.call(env)
14
11
  ensure
15
12
  begin
16
- if Thread.current[:bullet_notification_collector].notifications_present?
13
+ if ::Thread.current[:bullet_notification_collector].notifications_present?
17
14
  BulletmarkRepairer::Patcher.execute(
18
- notifications: Thread.current[:bullet_notification_collector],
15
+ notifications: ::Thread.current[:bullet_notification_collector],
19
16
  controller: env['action_dispatch.request.parameters']['controller'],
20
17
  action: env['action_dispatch.request.parameters']['action'],
21
- loaded_associations: Thread.current[:bulletmark_repaier_loaded_associations]
18
+ loaded_associations: BulletmarkRepairer::Thread.current
22
19
  )
23
20
  end
24
21
  rescue StandardError => e
25
22
  raise e if BulletmarkRepairer.config.debug?
26
23
  end
27
- Thread.current[:bulletmark_repaier_loaded_associations].clear
24
+ BulletmarkRepairer::Thread.clear
28
25
  end
29
26
  end
30
27
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+
5
+ module BulletmarkRepairer
6
+ class Thread
7
+ class << self
8
+ def current
9
+ touch
10
+ end
11
+
12
+ def add(name:, method_type:, args:)
13
+ touch
14
+ ::Thread.current[:bulletmark_repaier_loaded_associations][name][method_type].add(args)
15
+ end
16
+
17
+ def clear
18
+ ::Thread.current[:bulletmark_repaier_loaded_associations] = nil
19
+ end
20
+
21
+ private
22
+
23
+ def touch
24
+ ::Thread.current[:bulletmark_repaier_loaded_associations] ||= Hash.new do |hash, key|
25
+ hash[key] = { includes: Set.new, eager_load: Set.new, preload: Set.new }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BulletmarkRepairer
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
@@ -9,6 +9,7 @@ require 'bulletmark_repairer/corrector_builder'
9
9
  require 'bulletmark_repairer/loaded_associations'
10
10
  require 'bulletmark_repairer/markers'
11
11
  require 'bulletmark_repairer/patcher'
12
+ require 'bulletmark_repairer/thread'
12
13
 
13
14
  module BulletmarkRepairer
14
15
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulletmark_repairer
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
  - makicamel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -95,6 +95,7 @@ files:
95
95
  - lib/bulletmark_repairer/rack.rb
96
96
  - lib/bulletmark_repairer/railtie.rb
97
97
  - lib/bulletmark_repairer/retry_corrector.rb
98
+ - lib/bulletmark_repairer/thread.rb
98
99
  - lib/bulletmark_repairer/version.rb
99
100
  - sig/bulletmark_repairer.rbs
100
101
  homepage: https://github.com/makicamel/bulletmark_repairer
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  requirements: []
123
- rubygems_version: 3.4.10
124
+ rubygems_version: 3.1.4
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Auto corrector for N+1 queries detected at runtime with Bullet