class BulletinFeedCache include Mongoid::Document include Mongoid::Timestamps field :content, type: String, default: '' field :uid field :start field :end field :date field :invalid_date, type: DateTime def self.regenerate_all caches = BulletinFeedCache.all.to_a caches.each do |cache| cache.regenerate end 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 BulletinFeed.where(uid: uid).first.generate_one_cache(startdt: st,enddt: et,dt: dt) rescue nil self.destroy end end