Skip to content

Commit e03b66a

Browse files
sandbergjachristinachkevinreissmaxkadel
committed
[#3484] Add missing argument to Hash default proc
The proc to fill in a default value for a Hash accepts two arguments: the hash itself and then the key. Prior to this commit, our proc was only using the Hash, but was treating it as if it was a key. This had the potential to cause some serious performance problems when solr returned many facets or many facet values, when a huge hash was treated as a string and interpolated into other strings via Hash#inspect. Adding this missing argument ensures that we send the key/field_name, rather than the entire hash. For the provided test case on my laptop, this commit speed up null facet object generation up from 45 iterations/second to 18,700 iterations/second. It also doubles the performance of our advanced search form. This commit also adds the rspec-benchmark gem as a dev dependency -- I'm definitely open to figuring out a different way to test this if the additional dependency is not desired. Closes #3484 Co-authored-by: Christina Chortaria <[email protected]> Co-authored-by: Kevin Reiss <[email protected]> Co-authored-by: Max Kadel <[email protected]>
1 parent 491962f commit e03b66a

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

blacklight.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
4949
s.add_development_dependency "rubocop-capybara"
5050
s.add_development_dependency "rubocop-rspec_rails"
5151
s.add_development_dependency "rubocop-factory_bot"
52+
s.add_development_dependency "rspec-benchmark"
5253
s.add_development_dependency "i18n-tasks", '~> 1.0'
5354
s.add_development_dependency "solr_wrapper"
5455
end

lib/blacklight/solr/response/facets.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def merge_facet(name:, value:, hits: nil)
157157
# facet data in the response
158158
def default_aggregations
159159
@default_aggregations ||= begin
160-
h = Hash.new { |key| null_facet_field_object(key) }
160+
h = Hash.new { |_hash, key| null_facet_field_object(key) }
161161
h.with_indifferent_access
162162
end
163163
end

0 commit comments

Comments
 (0)