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
announcement_feed = BulletinFeed.new(feed_params)
announcement_feed.save
create_feed_cache(nil,announcement_feed)
feeds = BulletinFeed.all.asc(:created_at)
render :partial => "feed", :collection => feeds
end
@ -162,6 +163,7 @@ class Admin::AnnouncementsController < OrbitAdminController
ann_feed = BulletinFeed.find(params[:id])
ann_feed.update_attributes(feed_params)
ann_feed.save
create_feed_cache(nil,ann_feed)
feeds = BulletinFeed.all.asc(:created_at)
render :partial => "feed", :collection => feeds
end
@ -481,8 +483,19 @@ class Admin::AnnouncementsController < OrbitAdminController
params.require(:announcement_setting).permit!
end
def create_feed_cache(bulletin)
BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed|
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|
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
elsif !bulletin_feed.nil?
uid = bulletin_feed.uid
uri = URI(request.protocol + request.host_with_port + "/xhr/announcements/feed/#{uid}.json")
Thread.new do

View File

@ -31,8 +31,8 @@ class AnnouncementFeedsController < ApplicationController
end
respond_to do |format|
format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"}
format.rss
end
format.rss
end
end
def feeds

View File

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

View File

@ -10,7 +10,7 @@ module BulletinModel
AnnsCache.where(parent_id:self.id).destroy
elsif self.class == Bulletin || (self.class == Page && self.module == "announcement")
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
AnnsCache.all.destroy
end