Skip to content

Commit

Permalink
Remove product cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Yorkley committed Oct 4, 2019
1 parent ff00a85 commit 8c3eeab
Show file tree
Hide file tree
Showing 59 changed files with 18 additions and 1,797 deletions.
2 changes: 0 additions & 2 deletions .rubocop_manual_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ Metrics/LineLength:
- spec/helpers/order_cycles_helper_spec.rb
- spec/helpers/spree/admin/base_helper_spec.rb
- spec/jobs/confirm_order_job_spec.rb
- spec/jobs/products_cache_integrity_checker_job_spec.rb
- spec/jobs/refresh_products_cache_job_spec.rb
- spec/jobs/subscription_confirm_job_spec.rb
- spec/jobs/subscription_placement_job_spec.rb
- spec/lib/open_food_network/address_finder_spec.rb
Expand Down
27 changes: 0 additions & 27 deletions app/controllers/admin/cache_settings_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/api/order_cycles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open_food_network/products_renderer'

module Api
class OrderCyclesController < BaseController
include EnterprisesHelper
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/shop_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'open_food_network/cached_products_renderer'

class ShopController < BaseController
layout "darkswarm"
before_filter :require_distributor_chosen, :set_order_cycles, except: :changeable_orders_alert
Expand Down
30 changes: 0 additions & 30 deletions app/jobs/products_cache_integrity_checker_job.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/jobs/refresh_products_cache_job.rb

This file was deleted.

9 changes: 0 additions & 9 deletions app/models/coordinator_fee.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
class CoordinatorFee < ActiveRecord::Base
belongs_to :order_cycle
belongs_to :enterprise_fee

after_save :refresh_products_cache
after_destroy :refresh_products_cache

private

def refresh_products_cache
order_cycle.refresh_products_cache
end
end
8 changes: 0 additions & 8 deletions app/models/enterprise_fee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class EnterpriseFee < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :exchanges, through: :exchange_fees

after_save :refresh_products_cache
# After destroy, the products cache is refreshed via the after_destroy hook for
# coordinator_fees and exchange_fees

attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :inherits_tax_category

FEE_TYPES = %w(packing transport admin sales fundraising).freeze
Expand Down Expand Up @@ -59,8 +55,4 @@ def ensure_valid_tax_category_settings
end
true
end

def refresh_products_cache
OpenFoodNetwork::ProductsCache.enterprise_fee_changed self
end
end
11 changes: 0 additions & 11 deletions app/models/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Exchange < ActiveRecord::Base
validates :order_cycle, :sender, :receiver, presence: true
validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }

after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy

accepts_nested_attributes_for :variants

scope :in_order_cycle, lambda { |order_cycle| where(order_cycle_id: order_cycle) }
Expand Down Expand Up @@ -98,12 +95,4 @@ def role
def participant
incoming? ? sender : receiver
end

def refresh_products_cache
OpenFoodNetwork::ProductsCache.exchange_changed self
end

def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.exchange_destroyed self
end
end
9 changes: 0 additions & 9 deletions app/models/exchange_fee.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
class ExchangeFee < ActiveRecord::Base
belongs_to :exchange
belongs_to :enterprise_fee

after_save :refresh_products_cache
after_destroy :refresh_products_cache

private

def refresh_products_cache
exchange.refresh_products_cache
end
end
10 changes: 0 additions & 10 deletions app/models/inventory_item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'open_food_network/products_cache'

class InventoryItem < ActiveRecord::Base
attr_accessible :enterprise, :enterprise_id, :variant, :variant_id, :visible

Expand All @@ -13,12 +11,4 @@ class InventoryItem < ActiveRecord::Base

scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: false) }

after_save :refresh_products_cache

private

def refresh_products_cache
OpenFoodNetwork::ProductsCache.inventory_item_changed self
end
end
6 changes: 0 additions & 6 deletions app/models/order_cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class OrderCycle < ActiveRecord::Base
validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?

after_save :refresh_products_cache

preference :product_selection_from_coordinator_inventory_only, :boolean, default: false

scope :active, lambda {
Expand Down Expand Up @@ -247,10 +245,6 @@ def coordinated_by?(user)
coordinator.users.include? user
end

def refresh_products_cache
OpenFoodNetwork::ProductsCache.order_cycle_changed self
end

def items_bought_by_user(user, distributor)
# The Spree::Order.complete scope only checks for completed_at date
# it does not ensure state is "complete"
Expand Down
13 changes: 0 additions & 13 deletions app/models/producer_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ class ProducerProperty < ActiveRecord::Base

default_scope order("#{table_name}.position")

after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy

scope :ever_sold_by, ->(shop) {
joins(producer: { supplied_products: { variants: { exchanges: :order_cycle } } }).
merge(Exchange.outgoing).
Expand All @@ -29,14 +26,4 @@ def property_name=(name)
Spree::Property.create(name: name, presentation: name)
end
end

private

def refresh_products_cache
OpenFoodNetwork::ProductsCache.producer_property_changed self
end

def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.producer_property_destroyed self
end
end
7 changes: 0 additions & 7 deletions app/models/spree/classification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@
belongs_to :product, class_name: "Spree::Product", touch: true

before_destroy :dont_destroy_if_primary_taxon
after_destroy :refresh_products_cache
after_save :refresh_products_cache

private

def refresh_products_cache
product = Spree::Product.with_deleted.find(product_id) if product.blank?
product.refresh_products_cache
end

def dont_destroy_if_primary_taxon
if product.primary_taxon == taxon
errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name)
Expand Down
9 changes: 0 additions & 9 deletions app/models/spree/image_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Spree::Image.class_eval do
after_save :refresh_products_cache
after_destroy :refresh_products_cache

# Spree stores attachent definitions in JSON. This converts the style name and format to
# strings. However, when paperclip encounters these, it doesn't recognise the format.
# Here we solve that problem by converting format and style name to symbols.
Expand All @@ -23,10 +20,4 @@ def self.reformat_styles
end

reformat_styles

private

def refresh_products_cache
viewable.try :refresh_products_cache
end
end
7 changes: 0 additions & 7 deletions app/models/spree/option_type_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
module Spree
OptionType.class_eval do
has_many :products, through: :product_option_types
after_save :refresh_products_cache

private

def refresh_products_cache
products(:reload).each(&:refresh_products_cache)
end
end
end
18 changes: 0 additions & 18 deletions app/models/spree/option_value_decorator.rb

This file was deleted.

30 changes: 0 additions & 30 deletions app/models/spree/preference_decorator.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/models/spree/price_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Spree
Price.class_eval do
acts_as_paranoid without_default_scope: true

after_save :refresh_products_cache

# Allow prices to access associated soft-deleted variants.
def variant
Spree::Variant.unscoped { super }
Expand All @@ -16,9 +14,5 @@ def check_price
self.currency = Spree::Config[:currency]
end
end

def refresh_products_cache
variant.andand.refresh_products_cache
end
end
end
17 changes: 5 additions & 12 deletions app/models/spree/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
after_save :remove_previous_primary_taxon_from_taxons
after_save :ensure_standard_variant
after_save :update_units
after_save :refresh_products_cache

# -- Joins
scope :with_order_cycles_outer, -> {
Expand Down Expand Up @@ -192,23 +191,17 @@ def variant_unit_option_type

def destroy_with_delete_from_order_cycles
transaction do
OpenFoodNetwork::ProductsCache.product_deleted(self) do
touch_distributors
touch_distributors

ExchangeVariant.
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
select(:id)).destroy_all
ExchangeVariant.
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
select(:id)).destroy_all

destroy_without_delete_from_order_cycles
end
destroy_without_delete_from_order_cycles
end
end
alias_method_chain :destroy, :delete_from_order_cycles

def refresh_products_cache
OpenFoodNetwork::ProductsCache.product_changed self
end

private

def set_available_on_to_now
Expand Down
Loading

0 comments on commit 8c3eeab

Please sign in to comment.