2020-03-01 07:49:01 +00:00
|
|
|
module BulletinModel
|
|
|
|
module Cache
|
|
|
|
require 'active_support/concern'
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
2022-02-08 07:45:06 +00:00
|
|
|
after_save :do_before_save
|
|
|
|
after_destroy :do_before_save
|
2020-03-01 07:49:01 +00:00
|
|
|
end
|
|
|
|
def do_before_save
|
|
|
|
if self.class == SubPart
|
2022-03-29 08:41:21 +00:00
|
|
|
AnnsCache.where(parent_id: self.id).delete
|
2020-05-06 11:30:09 +00:00
|
|
|
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
|
2022-02-08 08:02:17 +00:00
|
|
|
tmp_cat_ids = (Array(self.category_id) + Array(self.org_category_id)).uniq
|
2021-08-13 04:42:14 +00:00
|
|
|
Thread.new do
|
2022-02-08 08:02:17 +00:00
|
|
|
BulletinFeedCache.where(:uid.in => BulletinFeed.any_of([{:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}},{:category_ids.in => tmp_cat_ids.collect{|v| v.to_s}}]).pluck(:uid)).each do |cache|
|
2021-08-13 04:42:14 +00:00
|
|
|
cache.regenerate
|
|
|
|
end
|
|
|
|
end
|
2020-07-20 15:48:24 +00:00
|
|
|
end
|
2022-03-29 08:41:21 +00:00
|
|
|
AnnsCache.all.delete
|
2020-03-01 07:49:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|