35 lines
1.3 KiB
Ruby
35 lines
1.3 KiB
Ruby
module EventNewsModel
|
|
module Cache
|
|
require 'active_support/concern'
|
|
extend ActiveSupport::Concern
|
|
included do
|
|
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
|
|
end
|
|
def do_before_save
|
|
if self.class == SubPart
|
|
::EventNewsCache.where(parent_id:self.id).destroy
|
|
elsif self.class == ::EventNews || (self.class == Page && self.module == "event_news_mod")
|
|
if self.class == ::EventNews
|
|
tmp_tag_ids = (Array(@tag_ids) + Array(@org_tag_ids)).uniq
|
|
tmp_cat_ids = (Array(@category_id) + Array(@org_category_id)).uniq
|
|
Thread.new do
|
|
::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|
|
|
cache.regenerate
|
|
end
|
|
end
|
|
end
|
|
::EventNewsCache.all.destroy
|
|
end
|
|
end
|
|
end
|
|
end |