From 9c728cc282d5eb85ab6b76dfa8ee52ee3e5e599a Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Sat, 12 Dec 2020 13:42:34 +0800 Subject: [PATCH] Revert "make whitelist thread safe" This reverts commit 9cda9c224a46786ecfa894480c4dd4d304db2adb. --- lib/bullet.rb | 17 +++++++++-------- spec/bullet_spec.rb | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/bullet.rb b/lib/bullet.rb index 39afbc1a..ab932d70 100644 --- a/lib/bullet.rb +++ b/lib/bullet.rb @@ -38,6 +38,7 @@ class << self :stacktrace_includes, :stacktrace_excludes, :skip_html_injection + attr_reader :whitelist attr_accessor :add_footer, :orm_patches_applied available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" } @@ -97,27 +98,27 @@ def stacktrace_excludes def add_whitelist(options) reset_whitelist - Thread.current[:whitelist][options[:type]][options[:class_name]] ||= [] - Thread.current[:whitelist][options[:type]][options[:class_name]] << options[:association].to_sym + @whitelist[options[:type]][options[:class_name]] ||= [] + @whitelist[options[:type]][options[:class_name]] << options[:association].to_sym end def delete_whitelist(options) reset_whitelist - Thread.current[:whitelist][options[:type]][options[:class_name]] ||= [] - Thread.current[:whitelist][options[:type]][options[:class_name]].delete(options[:association].to_sym) - Thread.current[:whitelist][options[:type]].delete_if { |_key, val| val.empty? } + @whitelist[options[:type]][options[:class_name]] ||= [] + @whitelist[options[:type]][options[:class_name]].delete(options[:association].to_sym) + @whitelist[options[:type]].delete_if { |_key, val| val.empty? } end def get_whitelist_associations(type, class_name) - Array(Thread.current[:whitelist][type][class_name]) + Array(@whitelist[type][class_name]) end def reset_whitelist - Thread.current[:whitelist] ||= { n_plus_one_query: {}, unused_eager_loading: {}, counter_cache: {} } + @whitelist ||= { n_plus_one_query: {}, unused_eager_loading: {}, counter_cache: {} } end def clear_whitelist - Thread.current[:whitelist] = nil + @whitelist = nil end def bullet_logger=(active) diff --git a/spec/bullet_spec.rb b/spec/bullet_spec.rb index ff252006..475ed4f8 100644 --- a/spec/bullet_spec.rb +++ b/spec/bullet_spec.rb @@ -88,7 +88,7 @@ it 'is deleted from the whitelist successfully' do Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department) Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department) - expect(Thread.current[:whitelist][:n_plus_one_query]).to eq({}) + expect(Bullet.whitelist[:n_plus_one_query]).to eq({}) end end