1
0
Fork 0
forked from OpenNeo/impress

oh poo, didn't commit these properly with the closet hanger caching :(

This commit is contained in:
Emi Matchu 2013-12-27 21:48:38 -05:00
parent b6247fa22f
commit 4a49ad2fe8
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,20 @@
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

View file

@ -0,0 +1,18 @@
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