oh poo, didn't commit these properly with the closet hanger caching :(
This commit is contained in:
parent
b6247fa22f
commit
4a49ad2fe8
2 changed files with 38 additions and 0 deletions
20
app/models/closet_hanger_observer.rb
Normal file
20
app/models/closet_hanger_observer.rb
Normal 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
|
18
app/models/closet_list_observer.rb
Normal file
18
app/models/closet_list_observer.rb
Normal 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
|
Loading…
Reference in a new issue