27 lines
684 B
Ruby
27 lines
684 B
Ruby
|
class ArchiveFileFeedCache
|
||
|
include Mongoid::Document
|
||
|
include Mongoid::Timestamps
|
||
|
|
||
|
field :content, type: String, default: ''
|
||
|
field :uid
|
||
|
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 = ArchiveFileFeed.all.pluck(:uid) - caches.collect(&:uid)
|
||
|
ArchiveFileFeed.where(:uid.in=> uids).each do |feed|
|
||
|
feed.generate_one_cache()
|
||
|
end
|
||
|
end
|
||
|
def regenerate
|
||
|
uid = self.uid
|
||
|
ArchiveFileFeed.where(uid: uid).each{|v| v.generate_one_cache} rescue nil
|
||
|
self.destroy
|
||
|
end
|
||
|
end
|