2022-01-21 02:09:31 +00:00
|
|
|
class EventNewsFeedCache
|
2024-09-16 03:30:37 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2022-01-21 02:09:31 +00:00
|
|
|
|
|
|
|
field :content, type: String, default: ''
|
|
|
|
field :uid
|
|
|
|
field :start
|
|
|
|
field :end
|
|
|
|
field :date
|
2024-09-16 03:30:37 +00:00
|
|
|
field :invalid_date, type: DateTime
|
|
|
|
def self.regenerate_all
|
|
|
|
caches = self.all.to_a
|
|
|
|
time_now = Time.now
|
|
|
|
caches.each do |cache|
|
|
|
|
if cache.invalid_date && cache.invalid_date <= time_now
|
|
|
|
cache.destroy
|
|
|
|
else
|
|
|
|
cache.regenerate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
uids = EventNewsFeed.all.pluck(:uid) - caches.collect(&:uid)
|
|
|
|
EventNewsFeed.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
|
|
|
|
EventNewsFeed.where(uid: uid).each{|v| v.generate_one_cache(startdt: st,enddt: et,dt: dt)} rescue nil
|
|
|
|
self.destroy
|
|
|
|
end
|
2021-09-16 09:16:20 +00:00
|
|
|
end
|