This commit is contained in:
BoHung Chiu 2021-11-29 11:01:28 +08:00
parent 5bb81c549b
commit 7fe6bbdde2
2 changed files with 8 additions and 6 deletions

View File

@ -2,9 +2,6 @@ require "rss"
class AnnouncementFeedsController < ApplicationController class AnnouncementFeedsController < ApplicationController
include Admin::AnnouncementsHelper include Admin::AnnouncementsHelper
def feed def feed
Thread.new do
BulletinFeedCache.all_of({:invalid_date.ne=>nil,:invalid_date.lte => Time.now}).delete_all
end
uid = params[:uid] uid = params[:uid]
startdt = params[:start].blank? ? nil : params[:start] startdt = params[:start].blank? ? nil : params[:start]
enddt = params[:end].blank? ? nil : params[:end] enddt = params[:end].blank? ? nil : params[:end]

View File

@ -10,8 +10,13 @@ class BulletinFeedCache
field :invalid_date, type: DateTime field :invalid_date, type: DateTime
def self.regenerate_all def self.regenerate_all
caches = self.all.to_a caches = self.all.to_a
time_now = Time.now
caches.each do |cache| caches.each do |cache|
if cache.invalid_date && cache.invalid_date <= time_now
cache.destroy
else
cache.regenerate cache.regenerate
end
end end
uids = BulletinFeed.all.pluck(:uid) - caches.collect(&:uid) uids = BulletinFeed.all.pluck(:uid) - caches.collect(&:uid)
BulletinFeed.where(:uid.in=> uids).each do |feed| BulletinFeed.where(:uid.in=> uids).each do |feed|