2020-03-01 07:49:01 +00:00
|
|
|
module BulletinModel
|
|
|
|
module Cache
|
|
|
|
require 'active_support/concern'
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
2022-05-10 10:42:14 +00:00
|
|
|
after_save :cache_tag_ids, :do_before_save
|
|
|
|
after_destroy :do_before_save
|
|
|
|
before_destroy :cache_tag_ids
|
|
|
|
end
|
|
|
|
def cache_tag_ids
|
2023-03-06 03:06:20 +00:00
|
|
|
if self.class == ::Bulletin
|
2022-05-11 03:32:10 +00:00
|
|
|
@tag_ids = self.tag_ids
|
|
|
|
@org_tag_ids = self.org_tag_ids
|
2022-05-22 10:44:30 +00:00
|
|
|
@category_id = self.category_id
|
|
|
|
@org_category_id = self.org_category_id
|
2022-05-11 03:32:10 +00:00
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
end
|
|
|
|
def do_before_save
|
2023-03-06 03:06:20 +00:00
|
|
|
if self.class == ::SubPart
|
|
|
|
::AnnsCache.where(parent_id: /^#{self.id}/).delete
|
|
|
|
elsif self.class == ::Bulletin || (self.class == ::Page && self.module == "announcement")
|
|
|
|
if self.class == ::Bulletin
|
2022-05-10 10:42:14 +00:00
|
|
|
tmp_tag_ids = (Array(@tag_ids) + Array(@org_tag_ids)).uniq
|
2022-05-22 10:44:30 +00:00
|
|
|
tmp_cat_ids = (Array(@category_id) + Array(@org_category_id)).uniq
|
2021-08-13 04:42:14 +00:00
|
|
|
Thread.new do
|
2023-03-06 03:06:20 +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)).to_a.each do |cache|
|
2021-08-13 04:42:14 +00:00
|
|
|
cache.regenerate
|
|
|
|
end
|
|
|
|
end
|
2020-07-20 15:48:24 +00:00
|
|
|
end
|
2023-03-06 03:06:20 +00:00
|
|
|
::AnnsCache.all.delete
|
2020-03-01 07:49:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|