Skip to content

Commit

Permalink
Merge pull request #1688 from jhawthorn/taxons_cache_key
Browse files Browse the repository at this point in the history
Replace cache_key_for_taxons with cache
  • Loading branch information
jhawthorn authored Jan 25, 2017
2 parents b19ff96 + c2d72ad commit 33797b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
comparisons. A comparison will fail if the two objects do not use the same
currency. [#1682](https://github.com/solidusio/solidus/pull/1682)

* Deprecations

* `cache_key_for_taxons` helper has been deprecated in favour of `cache [I18n.locale, @taxons]`

## Solidus 2.1.0 (unreleased)

* The OrderUpdater (as used by `order.update!`) now fully updates taxes.
Expand Down
5 changes: 5 additions & 0 deletions core/app/helpers/spree/store_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def store_menu?
end

def cache_key_for_taxons
Spree::Deprecation.warn <<-WARN.strip_heredoc
cache_key_for_taxons is deprecated. Rails >= 5 has built-in support for collection cache keys.
Instead in your view use:
cache [I18n.locale, @taxons] do
WARN
max_updated_at = @taxons.maximum(:updated_at).to_i
parts = [@taxon.try(:id), max_updated_at].compact.join("-")
"#{I18n.locale}/taxons/#{parts}"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/spree/shared/_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% @taxons = @taxon && @taxon.parent ? @taxon.parent.children : Spree::Taxon.roots %>
<%= form_tag spree.products_path, :method => :get do %>
<% cache(cache_key_for_taxons) do %>
<% cache [I18n.locale, @taxons] do %>
<%= select_tag :taxon,
options_for_select([[Spree.t(:all_departments), '']] +
@taxons.map {|t| [t.name, t.id]},
Expand Down
1 change: 0 additions & 1 deletion frontend/spec/features/caching/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
assert_written_to_cache("views/en/taxons/#{taxon.updated_at.utc.to_i}")

clear_cache_events
end
Expand Down
1 change: 0 additions & 1 deletion frontend/spec/features/caching/taxons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# warm up the cache
visit spree.root_path
assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
assert_written_to_cache("views/en/taxons/#{taxon.updated_at.utc.to_i}")

clear_cache_events
end
Expand Down

0 comments on commit 33797b4

Please sign in to comment.