Favoring explicit class declaration #17042
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Description
In helping track down #17041 I was looking at our cache
busting logic. We were looking up a constant via the
.const_get
callfrom a string already defined inline. This refactor short-circuits
naming a string, capitalizing it, then looking in the class's registered
constants.
There's also a subtle bug in the original; When
provider
equals"another_cache", the
#capitalize
method would return"Another_cache"
, whereas#classify
will return"AnotherCache"
.Below are some benchmarks for the change.
> bin/rails runner /Users/jfriesen/git/forem/bench.rb Rehearsal ------------------------------------------------ by_class 0.001239 0.000186 0.001425 ( 0.001342) by_const_get 0.011398 0.000136 0.011534 ( 0.011538) --------------------------------------- total: 0.012959sec user system total real by_class 0.000973 0.000030 0.001003 ( 0.000969) by_const_get 0.011102 0.000032 0.011134 ( 0.011104)
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
None, this is already tested.
UI accessibility concerns?
None.
Added/updated tests?
[Forem core team only] How will this change be communicated?