Skip to content

Commit

Permalink
Fix local dev environment caching bug on homepage & advanced search. …
Browse files Browse the repository at this point in the history
…Fixes TD-1417.

- Ensures that Rails.cache.fetch is not called when caching is false; this would sometimes lead to errors in a development environment
- Note you can run `rails dev:cache` in development to temporarily turn on caching for troubleshooting
  • Loading branch information
seanaery committed Feb 13, 2025
1 parent 76a17ca commit a9325e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.3
3.0.4
15 changes: 10 additions & 5 deletions lib/trln_argon/controller_override/solr_caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
module SolrCaching
extend ActiveSupport::Concern

# rubocop:disable Metrics/MethodLength
# We replicate much of core BL's index action here, but add logic
# around caching the response if it's cacheable. See:
# https://github.com/projectblacklight/blacklight/blob/release-8.x/app/controllers/concerns/blacklight/catalog.rb#L24-L51
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def cached_catalog_index
cat_index_cache_key = cache_key('cached_catalog_index')

@response =
if cat_index_cache_key.present? # cacheable
if cat_index_cache_key.present? && Rails.configuration.action_controller.perform_caching
cache_state = 'cacheable'
Rails.cache.fetch(cat_index_cache_key, expires_in: solr_cache_exp_time) do
cache_state = 'cache miss'
Expand All @@ -32,15 +35,15 @@ def cached_catalog_index
document_export_formats(format)
end
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

# rubocop:enable Metrics/MethodLength
def cached_advanced_index
return if request.method == :post

adv_index_cache_key = cache_key('cached_advanced_index')

@response =
if adv_index_cache_key.present? # cacheable
if adv_index_cache_key.present? && Rails.configuration.action_controller.perform_caching
cache_state = 'cacheable'
Rails.cache.fetch(adv_index_cache_key, expires_in: solr_cache_exp_time) do
cache_state = 'cache miss'
Expand Down Expand Up @@ -74,7 +77,9 @@ def solr_cache_exp_time

# We need to ensure that the query that populates the advanced search
# form (which has no search params) facets isn't limited to just the homepage
# facets (TD-1263).
# facets (TD-1263). So we essentially replicate core BL's advanced_search action,
# just with the home facet filters removed. See:
# https://github.com/projectblacklight/blacklight/blob/release-8.x/app/controllers/concerns/blacklight/catalog.rb#L53-L55
def advanced_search_form_data
@advanced_search_form_data ||=
blacklight_advanced_search_form_search_service.search_results do |builder|
Expand Down

0 comments on commit a9325e1

Please sign in to comment.