fix error

This commit is contained in:
邱博亞 2021-11-18 13:59:37 +08:00
parent 38e130664e
commit 430c673fdf
3 changed files with 10 additions and 2 deletions

View File

@ -22,11 +22,11 @@ class SiteFeed
end
end
before_destroy do
tmp = SiteFeedAnnc.where(feed_id: self.id).first
tmp = SiteFeedAnnc.where(feed_id: self.id)
main_directory = File.join("#{Rails.root}","public","site_feeds")
feed_directory = File.join(main_directory.to_s, self.id.to_s)
FileUtils.rm_rf(feed_directory.to_s)
if !tmp.nil?
if tmp.count!=0
tmp.destroy
end
end

View File

@ -16,6 +16,10 @@ Rails.application.routes.draw do
end
SiteFeedAnnc.where(:feed_id.nin=>SiteFeed.all.pluck(:id)).destroy
SiteFeed.each do |site_feed|
count = SiteFeedAnnc.where(feed_id: site_feed.id).count
if count>1
SiteFeedAnnc.where(feed_id: site_feed.id).limit(count-1).destroy
end
tmp = SiteFeedAnnc.where(feed_id: site_feed.id).first
if site_feed.disabled != true
if tmp.nil?

View File

@ -7,6 +7,10 @@ module FeedModel
before_save :do_before_save
end
def recreate_annc_cache(feed)
count = SiteFeedAnnc.where(feed_id: feed.id).count
if count>1
SiteFeedAnnc.where(feed_id: feed.id).limit(count-1).destroy
end
tmp = SiteFeedAnnc.where(feed_id: feed.id).first
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: feed.id)