daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Nov 14th, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. result = {}
  2. Brand.operating_review.each_shard do |brand|
  3.   puts "process.. #{brand.code}"
  4.   result[brand.code] ||= []
  5.   reviews = Review.joins(:sub_order).where('reviews.brand_user_id <> sub_orders.brand_user_id')
  6.   i = 0
  7.   c = reviews.count
  8.  
  9.   reviews.find_each do |review|
  10.     i += 1
  11.     print "\r#{i}/#{c}"
  12.  
  13.     old_sub_order_id = review.sub_order_id
  14.     sub_order_product_id = review.product.main_product? ? review.product.sub_product_ids.first : review.product_id
  15.     new_sub_order_id = review.brand_user.sub_order_for(sub_order_product_id)&.id
  16.     if new_sub_order_id != old_sub_order_id
  17.       review.update_columns(sub_order_id: new_sub_order_id)
  18.       review.detail.update!(calculated_mileage_dirty: true)
  19.       result[brand.code] << old_sub_order_id
  20.     end
  21.     # puts "before: sub_order_#{old_sub_order_id}, after: sub_order_#{review.sub_order_id}" if review.changed?
  22.   rescue => e
  23.     puts "\n#{e}\n"
  24.   end
  25. rescue => e
  26.   puts "\n#{e}\n"
  27. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top