fix feed cache error
This commit is contained in:
parent
36ac6d8146
commit
5e7873285f
|
@ -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,8 +483,19 @@ 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)
|
||||||
BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed|
|
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
|
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")
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
|
|
@ -31,8 +31,8 @@ class AnnouncementFeedsController < ApplicationController
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"}
|
format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"}
|
||||||
format.rss
|
format.rss
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def feeds
|
def feeds
|
||||||
|
|
|
@ -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
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue