announcement-test/lib/announcement/migrate.rb

42 lines
1.3 KiB
Ruby

module Announcement
module Migrate
def self.call
puts ['announcement migrate start']
gem_root = Announcement::Engine.root
require File.join(gem_root, 'app/models/announcement_setting')
require File.join(gem_root, 'app/models/bulletin')
require File.join(gem_root, 'app/models/bulletin_feed')
require File.join(gem_root, 'app/models/bulletin_feed_cache')
require File.join(Announcement::Engine.root, 'app/models/anns_cache')
setting = AnnouncementSetting.first
if !setting.migrate_flag.include?("v1")
Bulletin.all.pluck(:id, :title).each do |id, title_translations|
if title_translations.nil?
next
end
Bulletin.where(id: id).view.update_many({
"$set" => {
title_plain_text: OrbitHelper.get_plain_text_translations(title_translations)
}
})
end
setting.migrate_flag << "v1"
setting.save
end
AnnsCache.all.delete
#solve bug for thousands of generated feed cache
if BulletinFeedCache.count > BulletinFeed.count*5
BulletinFeedCache.collection.drop
end
BulletinFeedCache.regenerate_all
puts ['announcement migrate end']
end
end
end