fix feed cache error

This commit is contained in:
chiu 2020-07-22 11:11:58 +08:00
parent 36ac6d8146
commit 5e7873285f
4 changed files with 21 additions and 6 deletions

View File

@ -154,6 +154,7 @@ class Admin::AnnouncementsController < OrbitAdminController
def createfeed def createfeed
announcement_feed = BulletinFeed.new(feed_params) announcement_feed = BulletinFeed.new(feed_params)
announcement_feed.save announcement_feed.save
create_feed_cache(nil,announcement_feed)
feeds = BulletinFeed.all.asc(:created_at) feeds = BulletinFeed.all.asc(:created_at)
render :partial => "feed", :collection => feeds render :partial => "feed", :collection => feeds
end end
@ -162,6 +163,7 @@ class Admin::AnnouncementsController < OrbitAdminController
ann_feed = BulletinFeed.find(params[:id]) ann_feed = BulletinFeed.find(params[:id])
ann_feed.update_attributes(feed_params) ann_feed.update_attributes(feed_params)
ann_feed.save ann_feed.save
create_feed_cache(nil,ann_feed)
feeds = BulletinFeed.all.asc(:created_at) feeds = BulletinFeed.all.asc(:created_at)
render :partial => "feed", :collection => feeds render :partial => "feed", :collection => feeds
end end
@ -481,7 +483,8 @@ class Admin::AnnouncementsController < OrbitAdminController
params.require(:announcement_setting).permit! params.require(:announcement_setting).permit!
end end
def create_feed_cache(bulletin) def create_feed_cache(bulletin=nil,bulletin_feed=nil)
if !bulletin.nil?
BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed| BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed|
uid = bulletin_feed.uid uid = bulletin_feed.uid
uri = URI(request.protocol + request.host_with_port + "/xhr/announcements/feed/#{uid}.json") uri = URI(request.protocol + request.host_with_port + "/xhr/announcements/feed/#{uid}.json")
@ -492,5 +495,15 @@ class Admin::AnnouncementsController < OrbitAdminController
end end
end end
end end
elsif !bulletin_feed.nil?
uid = bulletin_feed.uid
uri = URI(request.protocol + request.host_with_port + "/xhr/announcements/feed/#{uid}.json")
Thread.new do
res_net = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',open_timeout: 60,read_timeout: 60) do |http|
req = Net::HTTP::Get.new(uri)
http.request(req)
end
end
end
end end
end end

View File

@ -5,5 +5,7 @@ class BulletinFeed
field :title, as: :slug_title, type: String, localize: true field :title, as: :slug_title, type: String, localize: true
field :tag_ids, type: Array, default: [] field :tag_ids, type: Array, default: []
before_save do
BulletinFeedCache.where(uid: self.uid).destroy
end
end end

View File

@ -10,7 +10,7 @@ module BulletinModel
AnnsCache.where(parent_id:self.id).destroy AnnsCache.where(parent_id:self.id).destroy
elsif self.class == Bulletin || (self.class == Page && self.module == "announcement") elsif self.class == Bulletin || (self.class == Page && self.module == "announcement")
if self.class == Bulletin if self.class == Bulletin
BulletinFeedCache.where(:tag_ids.in => Array(self.tag_ids).collect{|v| v.to_s}).destroy BulletinFeedCache.where(:uid.in => BulletinFeed.where(:tag_ids.in => Array(self.tag_ids).collect{|v| v.to_s}).pluck(:uid)).destroy
end end
AnnsCache.all.destroy AnnsCache.all.destroy
end end