-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change Bullet's feature enable logic #738
base: main
Are you sure you want to change the base?
Conversation
@koya1616 looks like a good solution, but it broke the tests, please take a look. |
99817ee
to
f1c665e
Compare
@flyerhzm |
lib/bullet.rb
Outdated
|
||
@n_plus_one_query_enable ||= true | ||
@unused_eager_loading_enable ||= true | ||
@counter_cache_enable ||= true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koya1616 this confused me, does it always set these three instance variables to true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flyerhzm
I’m sorry, I misunderstood. I’ve updated it so that it only returns true when the value is nil.
@n_plus_one_query_enable = true if @n_plus_one_query_enable.nil?
@unused_eager_loading_enable = true if @unused_eager_loading_enable.nil?
@counter_cache_enable = true if @counter_cache_enable.nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this way, it's confused that we set @n_plus_one_query_enable = true
when we call Bullet.enable = false
.
what about giving the instance variable a default value, so that we don't need to do it in enable=
method.
class << self
@n_plus_one_query_enable = true
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It seems there are cases, as you suggested in your writing style, where class instance variables such as @n_plus_one_query_enable defined within a class << self block are not properly initialized.
As a solution, I'm thinking of creating an initialization method and calling that method to initialize them.
Where do you think I should call this function from? Or is there another better approach?
def initialize_detectors
@n_plus_one_query_enable = true
@unused_eager_loading_enable = true
@counter_cache_enable = true
end
f1c665e
to
3d09361
Compare
3d09361
to
6dc2c90
Compare
fix #703
This pull request includes changes to the
lib/bullet.rb
file to improve the handling of feature enablement flags by introducing default values and refactoring the enablement checks.Refactoring of feature enablement flags:
lib/bullet.rb
: Modified theenable=
method to set default values for@n_plus_one_query_enable
,@unused_eager_loading_enable
, and@counter_cache_enable
if they are not already set.lib/bullet.rb
: Refactored then_plus_one_query_enable?
,unused_eager_loading_enable?
, andcounter_cache_enable?
methods to use new helper methods (default_n_plus_one_query_enable?
,default_unused_eager_loading_enable?
, anddefault_counter_cache_enable?
) for checking the default values.Is there any reason why it is set up this?
If there isn't any special reason, I think
@n_plus_one_query_enable
,@unused_eager_loading_enable
, and@counter_cache_enable
don't need to be reset. Since there's anenable? &&
check in the function below, it seems there wouldn't be any impact.def n_plus_one_query_enable?
def unused_eager_loading_enable?
def counter_cache_enable?