announcement-test/lib/bulletin_model/cache.rb

24 lines
770 B
Ruby
Raw Normal View History

module BulletinModel
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
AnnsCache.where(parent_id:self.id).destroy
elsif self.class == Bulletin || (self.class == Page && self.module == "announcement")
2020-07-20 15:48:24 +00:00
if self.class == Bulletin
2020-09-01 06:56:25 +00:00
tmp_tag_ids = (Array(self.tag_ids) + Array(self.org_tag_ids)).uniq
2021-08-13 04:42:14 +00:00
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
2020-07-20 15:48:24 +00:00
end
AnnsCache.all.destroy
end
end
end
end