mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Merge pull request #5486 from Matt-Yorkley/3-0-caching
[Spree 2.1] Caching
This commit is contained in:
@@ -37,25 +37,31 @@ class CacheService
|
||||
# Rails' caching in views is called "Fragment Caching" and uses some slightly different logic.
|
||||
# Note: keys supplied here are actually prepended with "views/" under the hood.
|
||||
|
||||
def self.ams_all_taxons_key
|
||||
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}"
|
||||
def self.ams_all_taxons
|
||||
[
|
||||
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}",
|
||||
{ skip_digest: true }
|
||||
]
|
||||
end
|
||||
|
||||
def self.ams_all_properties_key
|
||||
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}"
|
||||
def self.ams_all_properties
|
||||
[
|
||||
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}",
|
||||
{ skip_digest: true }
|
||||
]
|
||||
end
|
||||
|
||||
def self.ams_shops
|
||||
[
|
||||
"shops/index/inject_enterprises",
|
||||
{ expires_in: SHOPS_EXPIRY }
|
||||
{ expires_in: SHOPS_EXPIRY, skip_digest: true }
|
||||
]
|
||||
end
|
||||
|
||||
def self.ams_shop(enterprise)
|
||||
[
|
||||
"enterprises/shop/inject_enterprise_shopfront-#{enterprise.id}",
|
||||
{ expires_in: SHOPS_EXPIRY }
|
||||
{ expires_in: SHOPS_EXPIRY, skip_digest: true }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,9 +48,9 @@
|
||||
= inject_current_hub
|
||||
= inject_current_user
|
||||
= inject_rails_flash
|
||||
- cache CacheService::FragmentCaching.ams_all_taxons_key do
|
||||
- cache(*CacheService::FragmentCaching.ams_all_taxons) do
|
||||
= inject_taxons
|
||||
- cache CacheService::FragmentCaching.ams_all_properties_key do
|
||||
- cache(*CacheService::FragmentCaching.ams_all_properties) do
|
||||
= inject_properties
|
||||
= inject_current_order
|
||||
= inject_currency_config
|
||||
|
||||
@@ -18,8 +18,8 @@ feature "Darkswarm data caching", js: true, caching: true do
|
||||
|
||||
describe "caching injected taxons and properties" do
|
||||
it "caches taxons and properties" do
|
||||
expect(Spree::Taxon).to receive(:all) { [taxon] }
|
||||
expect(Spree::Property).to receive(:all) { [property] }
|
||||
expect(Spree::Taxon).to receive(:all).at_least(:once).and_call_original
|
||||
expect(Spree::Property).to receive(:all).at_least(:once).and_call_original
|
||||
|
||||
visit shops_path
|
||||
|
||||
@@ -29,14 +29,14 @@ feature "Darkswarm data caching", js: true, caching: true do
|
||||
visit shops_path
|
||||
end
|
||||
|
||||
xit "invalidates caches for taxons and properties" do
|
||||
it "invalidates caches for taxons and properties" do
|
||||
visit shops_path
|
||||
|
||||
taxon_timestamp1 = CacheService.latest_timestamp_by_class(Spree::Taxon)
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons_key}"
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons[0]}"
|
||||
|
||||
property_timestamp1 = CacheService.latest_timestamp_by_class(Spree::Property)
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties_key}"
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties[0]}"
|
||||
|
||||
toggle_filters
|
||||
|
||||
@@ -54,10 +54,10 @@ feature "Darkswarm data caching", js: true, caching: true do
|
||||
visit shops_path
|
||||
|
||||
taxon_timestamp2 = CacheService.latest_timestamp_by_class(Spree::Taxon)
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons_key}"
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons[0]}"
|
||||
|
||||
property_timestamp2 = CacheService.latest_timestamp_by_class(Spree::Property)
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties_key}"
|
||||
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties[0]}"
|
||||
|
||||
expect(taxon_timestamp1).to_not eq taxon_timestamp2
|
||||
expect(property_timestamp1).to_not eq property_timestamp2
|
||||
|
||||
@@ -47,8 +47,8 @@ feature "Shops caching", js: true, caching: true do
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
|
||||
|
||||
let(:test_domain) { "#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}" }
|
||||
let(:taxons_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/taxons?distributor=#{distributor.id}" }
|
||||
let(:properties_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/properties?distributor=#{distributor.id}" }
|
||||
let(:taxons_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/taxons?distributor=#{distributor.id}.json" }
|
||||
let(:properties_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/properties?distributor=#{distributor.id}.json" }
|
||||
let(:options) { { expires_in: CacheService::FILTERS_EXPIRY } }
|
||||
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user