From 2de9e9f45a81550788da765de5e9e2beec8db367 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 2 Aug 2023 12:25:57 -0700 Subject: [PATCH] Stop caching trade users on item page Idk this one might actually be a bit of a pain to load? But I'd want to optimize it differently anyway, and there's overhauls we're already planning to do here. --- app/models/closet_hanger_observer.rb | 20 -------------------- app/models/closet_list.rb | 1 - app/models/closet_list_observer.rb | 18 ------------------ app/models/user_sweeper.rb | 8 -------- app/views/items/show.html.haml | 20 +++++++++----------- config/application.rb | 4 ---- 6 files changed, 9 insertions(+), 62 deletions(-) delete mode 100644 app/models/closet_hanger_observer.rb delete mode 100644 app/models/closet_list_observer.rb delete mode 100644 app/models/user_sweeper.rb diff --git a/app/models/closet_hanger_observer.rb b/app/models/closet_hanger_observer.rb deleted file mode 100644 index b00938e0..00000000 --- a/app/models/closet_hanger_observer.rb +++ /dev/null @@ -1,20 +0,0 @@ -class ClosetHangerObserver < ActionController::Caching::Sweeper - extend FragmentExpiration - - def after_create(hanger) - self.class.expire_item_trade_hangers(hanger) if hanger.trading? - end - - def after_update(hanger) - self.class.expire_item_trade_hangers(hanger) if hanger.list_id_changed? - end - - def after_destroy(hanger) - self.class.expire_item_trade_hangers(hanger) if hanger.trading? - end - - def self.expire_item_trade_hangers(hanger) - expire_fragment_in_all_locales("items/#{hanger.item_id} trade_hangers") - expire_fragment_in_all_locales("items/#{hanger.item_id} trade_hangers owned=#{hanger.owned}") - end -end diff --git a/app/models/closet_list.rb b/app/models/closet_list.rb index dd02da61..bf6a9e55 100644 --- a/app/models/closet_list.rb +++ b/app/models/closet_list.rb @@ -1,7 +1,6 @@ class ClosetList < ActiveRecord::Base belongs_to :user has_many :hangers, :class_name => 'ClosetHanger', :foreign_key => 'list_id' - # Nullification of associated records occurs in the ClosetListObserver. validates :name, :presence => true, :uniqueness => {:scope => :user_id} validates :user, :presence => true diff --git a/app/models/closet_list_observer.rb b/app/models/closet_list_observer.rb deleted file mode 100644 index a1be4910..00000000 --- a/app/models/closet_list_observer.rb +++ /dev/null @@ -1,18 +0,0 @@ -class ClosetListObserver < ActionController::Caching::Sweeper - include FragmentExpiration - - def after_update(list) - expire_all_items_trade_hangers(list) if list.trading_changed? - end - - def before_destroy(list) - # Nullify all the child records explicitly, which will in turn trigger - # their update callbacks and expire their items' caches. This occurs in the - # same transaction as the list's destruction. - list.hangers.each { |h| h.list_id = nil; h.save! } - end - - def expire_all_items_trade_hangers(list) - list.hangers.each { |h| ClosetHangerObserver.expire_item_trade_hangers(h) } - end -end \ No newline at end of file diff --git a/app/models/user_sweeper.rb b/app/models/user_sweeper.rb deleted file mode 100644 index eabc7b2d..00000000 --- a/app/models/user_sweeper.rb +++ /dev/null @@ -1,8 +0,0 @@ -class UserSweeper < ActionController::Caching::Sweeper - observe User - def after_update(user) - # Delegate null-list sweeping to the ClosetListObserver. - null_lists = [true, false].map { |owned| user.null_closet_list(owned) } - null_lists.each { |list| ClosetListObserver.instance.after_update(list) } - end -end diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 923ca7e2..929cb0ec 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -59,17 +59,15 @@ - else = list_zones @restricted_zones -- localized_cache "items/#{@item.id} trade_hangers" do - #trade-hangers - - [true, false].each do |owned| - - localized_cache "items/#{@item.id} trade_hangers owned=#{owned}" do - %p - %strong - = trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size) - = render_trading_closet_hangers(owned) - %span.toggle - %span.more= t '.trading_closet_hangers.show_more' - %span.less= t '.trading_closet_hangers.show_less' +#trade-hangers + - [true, false].each do |owned| + %p + %strong + = trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size) + = render_trading_closet_hangers(owned) + %span.toggle + %span.more= t '.trading_closet_hangers.show_more' + %span.less= t '.trading_closet_hangers.show_less' #item-preview-header %h3= t '.preview.header' diff --git a/config/application.rb b/config/application.rb index 6dfe87b1..57c8e73d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,10 +12,6 @@ module OpenneoImpressItems # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - # Activate observers that should always be running - config.active_record.observers = [:closet_hanger_observer, - :closet_list_observer, :user_sweeper] - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)'