event_news/lib/event_news_model/cache.rb

24 lines
814 B
Ruby
Raw Normal View History

2022-01-21 02:09:31 +00:00
module EventNewsModel
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
2023-03-06 02:43:31 +00:00
::EventNewsCache.where(parent_id:self.id).destroy
elsif self.class == ::EventNews || (self.class == Page && self.module == "event_news")
if self.class == ::EventNews
2022-01-21 02:09:31 +00:00
tmp_tag_ids = (Array(self.tag_ids) + Array(self.org_tag_ids)).uniq
Thread.new do
2023-03-06 02:43:31 +00:00
::EventNewsCache.where(:uid.in => ::EventNewsFeed.where(:tag_ids.in => tmp_tag_ids.collect{|v| v.to_s}).pluck(:uid)).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