announcement-test/app/models/bulletin_feed_cache.rb

34 lines
833 B
Ruby
Raw Normal View History

2020-07-20 15:48:24 +00:00
class BulletinFeedCache
include Mongoid::Document
include Mongoid::Timestamps
field :content, type: String, default: ''
field :uid
2021-08-13 04:42:14 +00:00
field :start
field :end
field :date
field :invalid_date, type: DateTime
def self.regenerate_all
2021-09-16 09:15:44 +00:00
caches = self.all.to_a
2021-11-29 03:01:28 +00:00
time_now = Time.now
caches.each do |cache|
if cache.invalid_date && cache.invalid_date <= time_now
cache.destroy
else
cache.regenerate
end
end
2021-08-13 04:42:14 +00:00
uids = BulletinFeed.all.pluck(:uid) - caches.collect(&:uid)
BulletinFeed.where(:uid.in=> uids).each do |feed|
feed.generate_one_cache()
end
end
def regenerate
st = self.start
et = self.end
dt = self.date
uid = self.uid
2021-11-18 07:07:34 +00:00
BulletinFeed.where(uid: uid).each{|v| v.generate_one_cache(startdt: st,enddt: et,dt: dt)} rescue nil
2021-08-13 04:42:14 +00:00
self.destroy
end
2020-07-20 15:48:24 +00:00
end