OptimizedImage.where("upload_id NOT IN (SELECT id FROM uploads)").destroy_all
# migrate optimized_images to new scheme
problems=OptimizedImage.migrate_to_new_scheme
problems.eachdo|hash|
optimized_image_id=hash[:optimized_image].id
Discourse.handle_job_exception(hash[:ex],error_context(args,"Migrating optimized_image id #{optimized_image_id}",optimized_image_id:optimized_image_id))