- Rake::Task.define_task 'df:refresh_oneboxes', [:delay] => :environment do |_, args|
- require 'post'
- require 'rake/task'
- require 'site_setting_extension'
- args.with_defaults(delay: 5)
- delay = args[:delay]&.to_i
- puts "Rebaking post markdown for '#{RailsMultisite::ConnectionManagement.current_db}'"
- disable_edit_notifications = SiteSetting.disable_edit_notifications
- SiteSetting.disable_edit_notifications = true
- total = Post.count
- count = 0
- Post.find_each do |post|
- count += 1
- post.df_delay_for = (delay * count).seconds
- post.rebake!(invalidate_oneboxes: true)
- print "\r%9d / %d (%5.1f%%)" % [count, total, ((count.to_f / total.to_f) * 100).round(1)]
- end
- SiteSetting.disable_edit_notifications = disable_edit_notifications
- puts "", "#{count} posts done!", "-" * 50
- end