feeds/lib/feed_model/cache.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

module FeedModel
module Cache
require 'active_support/concern'
extend ActiveSupport::Concern
included do
before_save :do_before_save
end
def recreate_annc_cache(feed)
tmp = SiteFeedAnnc.where(feed_id: feed.id).first
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: feed.id)
end
tmp[:feed_name] = feed[:feed_name]
tmp.all_contents_for_feed = feed.get_annc
tmp.merge_with_category = feed.merge_with_category
2020-04-08 13:13:02 +00:00
tmp.channel_key = feed.channel_key
tmp.category_title = feed.category[:title] rescue {}
tmp.remote_site_url = feed.remote_site_url
tmp.channel_title = feed.channel_title_for_cache
tmp.save
end
def do_before_save
if self.class == Category
2020-07-20 05:07:01 +00:00
Thread.new do
SiteFeedAnnc.where(merge_with_category: self.id.to_s).each do |site_feed_annc|
recreate_annc_cache(site_feed_annc)
end
end
elsif self.class == SiteFeed
if self.disabled != true
2020-07-20 05:07:01 +00:00
Thread.new do
recreate_annc_cache(self)
end
else
tmp = SiteFeedAnnc.where(feed_id: self.id).first
if !tmp.nil?
tmp.destroy
end
end
end
end
end
end