2020-04-05 14:36:09 +00:00
|
|
|
module FeedModel
|
|
|
|
module Cache
|
|
|
|
require 'active_support/concern'
|
|
|
|
extend ActiveSupport::Concern
|
2021-09-15 16:06:43 +00:00
|
|
|
extend self
|
2020-04-05 14:36:09 +00:00
|
|
|
included do
|
|
|
|
before_save :do_before_save
|
|
|
|
end
|
|
|
|
def recreate_annc_cache(feed)
|
2021-11-18 05:59:37 +00:00
|
|
|
count = SiteFeedAnnc.where(feed_id: feed.id).count
|
|
|
|
if count>1
|
|
|
|
SiteFeedAnnc.where(feed_id: feed.id).limit(count-1).destroy
|
|
|
|
end
|
2020-04-05 14:36:09 +00:00
|
|
|
tmp = SiteFeedAnnc.where(feed_id: feed.id).first
|
|
|
|
if tmp.nil?
|
|
|
|
tmp = SiteFeedAnnc.new(feed_id: feed.id)
|
|
|
|
end
|
2021-11-09 10:11:11 +00:00
|
|
|
tmp.all_contents_for_feed = tmp.cache_annc(true)
|
2022-09-25 11:34:29 +00:00
|
|
|
feed.sync_data_to_annc(tmp)
|
2020-04-05 14:36:09 +00:00
|
|
|
tmp.save
|
2022-05-22 10:36:26 +00:00
|
|
|
if feed.feeds_model && feed.feeds_finish_callback
|
|
|
|
feeds_model = feed.feeds_model.constantize
|
|
|
|
feeds_model.send(feed.feeds_finish_callback, "update_all", {"data"=>feed.get_annc(false),"feed_id"=>feed.id,"category_id"=>feed.merge_with_category})
|
|
|
|
end
|
2020-04-05 14:36:09 +00:00
|
|
|
end
|
|
|
|
def do_before_save
|
2022-05-22 10:36:26 +00:00
|
|
|
unless @skip_callback
|
|
|
|
if self.class == Category
|
2020-07-20 05:07:01 +00:00
|
|
|
Thread.new do
|
2022-12-07 04:04:47 +00:00
|
|
|
SiteFeed.where(merge_with_category: self.id.to_s).each do |site_feed|
|
|
|
|
recreate_annc_cache(site_feed)
|
2022-05-22 10:36:26 +00:00
|
|
|
end
|
2020-07-20 05:07:01 +00:00
|
|
|
end
|
2022-05-22 10:36:26 +00:00
|
|
|
elsif self.class == SiteFeed
|
|
|
|
if self.disabled != true
|
|
|
|
Thread.new do
|
|
|
|
recreate_annc_cache(self)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tmp = SiteFeedAnnc.where(feed_id: self.id).first
|
|
|
|
if !tmp.nil?
|
|
|
|
tmp.destroy
|
|
|
|
end
|
2020-04-05 14:36:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|