25 lines
807 B
Ruby
25 lines
807 B
Ruby
module BulletinModel
|
|
module Cache
|
|
require 'active_support/concern'
|
|
extend ActiveSupport::Concern
|
|
included do
|
|
before_save :do_before_save
|
|
before_destroy :do_before_save
|
|
end
|
|
def do_before_save
|
|
if self.class == SubPart
|
|
AnnsCache.where(parent_id:self.id).destroy
|
|
elsif self.class == Bulletin || (self.class == Page && self.module == "announcement")
|
|
if self.class == Bulletin
|
|
tmp_tag_ids = (Array(self.tag_ids) + Array(self.org_tag_ids)).uniq
|
|
Thread.new do
|
|
BulletinFeedCache.where(:uid.in => BulletinFeed.where(:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}).pluck(:uid)).each do |cache|
|
|
cache.regenerate
|
|
end
|
|
end
|
|
end
|
|
AnnsCache.all.destroy
|
|
end
|
|
end
|
|
end
|
|
end |