Application_Form/custom_announcement/lib/custom_bulletin_model/cache.rb

20 lines
724 B
Ruby

module CustomBulletinModel
module Cache
require 'active_support/concern'
extend ActiveSupport::Concern
included do
before_save :do_before_save
end
def do_before_save
if self.class == SubPart
CustomAnnsCache.where(parent_id:self.id).destroy
elsif self.class == CustomBulletin || (self.class == Page && self.module == "custom_announcement")
if self.class == CustomBulletin
tmp_tag_ids = (Array(self.tag_ids) + Array(self.org_tag_ids)).uniq
CustomBulletinFeedCache.where(:uid.in => CustomBulletinFeed.where(:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}).pluck(:uid)).destroy
end
CustomAnnsCache.all.destroy
end
end
end
end