forked from OpenNeo/impress
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.
This commit is contained in:
parent
44341ba731
commit
a4a0188b1b
6 changed files with 9 additions and 62 deletions
|
@ -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
|
|
|
@ -1,7 +1,6 @@
|
||||||
class ClosetList < ActiveRecord::Base
|
class ClosetList < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :hangers, :class_name => 'ClosetHanger', :foreign_key => 'list_id'
|
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 :name, :presence => true, :uniqueness => {:scope => :user_id}
|
||||||
validates :user, :presence => true
|
validates :user, :presence => true
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -59,10 +59,8 @@
|
||||||
- else
|
- else
|
||||||
= list_zones @restricted_zones
|
= list_zones @restricted_zones
|
||||||
|
|
||||||
- localized_cache "items/#{@item.id} trade_hangers" do
|
|
||||||
#trade-hangers
|
#trade-hangers
|
||||||
- [true, false].each do |owned|
|
- [true, false].each do |owned|
|
||||||
- localized_cache "items/#{@item.id} trade_hangers owned=#{owned}" do
|
|
||||||
%p
|
%p
|
||||||
%strong
|
%strong
|
||||||
= trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size)
|
= trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size)
|
||||||
|
|
|
@ -12,10 +12,6 @@ module OpenneoImpressItems
|
||||||
# Application configuration should go into files in config/initializers
|
# Application configuration should go into files in config/initializers
|
||||||
# -- all .rb files in that directory are automatically loaded.
|
# -- 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.
|
# 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.
|
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||||
# config.time_zone = 'Central Time (US & Canada)'
|
# config.time_zone = 'Central Time (US & Canada)'
|
||||||
|
|
Loading…
Reference in a new issue