2022-01-21 02:09:31 +00:00
|
|
|
module EventNewsModel
|
|
|
|
module Cache
|
|
|
|
require 'active_support/concern'
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
2024-09-16 03:30:37 +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
|
|
|
|
if self.class == ::EventNews
|
|
|
|
@tag_ids = self.tag_ids
|
|
|
|
@org_tag_ids = self.org_tag_ids
|
|
|
|
@category_id = self.category_id
|
|
|
|
@org_category_id = self.org_category_id
|
|
|
|
end
|
2022-01-21 02:09:31 +00:00
|
|
|
end
|
|
|
|
def do_before_save
|
|
|
|
if self.class == SubPart
|
2023-03-06 02:43:31 +00:00
|
|
|
::EventNewsCache.where(parent_id:self.id).destroy
|
2024-09-16 03:30:37 +00:00
|
|
|
elsif self.class == ::EventNews || (self.class == Page && self.module == "event_news_mod")
|
2023-03-06 02:43:31 +00:00
|
|
|
if self.class == ::EventNews
|
2024-09-16 03:30:37 +00:00
|
|
|
tmp_tag_ids = (Array(@tag_ids) + Array(@org_tag_ids)).uniq
|
|
|
|
tmp_cat_ids = (Array(@category_id) + Array(@org_category_id)).uniq
|
2022-01-21 02:09:31 +00:00
|
|
|
Thread.new do
|
2024-09-16 03:30:37 +00:00
|
|
|
::EventNewsFeedCache.where(:uid.in => ::EventNewsFeed.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|
|
2022-01-21 02:09:31 +00:00
|
|
|
cache.regenerate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-03-06 02:43:31 +00:00
|
|
|
::EventNewsCache.all.destroy
|
2022-01-21 02:09:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-22 02:23:36 +00:00
|
|
|
end
|