Skip to content

Instantly share code, notes, and snippets.

@purintai
Last active October 19, 2016 05:49
Show Gist options
  • Save purintai/da611bf1e33ee6a77abcb571d5e01800 to your computer and use it in GitHub Desktop.
Save purintai/da611bf1e33ee6a77abcb571d5e01800 to your computer and use it in GitHub Desktop.
touch or delete (if csv rows over 500k)
csv = CSV.open(path, headers: true)
touched = []
csv.each do |row|
params = row.to_h
ProductUpdateWorker.perform_async(params)
touched << params['code']
end
Product.where.not(code: touched).destroy_all
csv = CSV.open(path, headers: true)
begin_at = Time.zone.now
csv.each do |row|
params = row.to_h
ProductUpdateWorker.perform_async(params)
Product.find_by(code: params['code'])&.touch
end
Product.where('updated_at < ?', begin_at).destroy_all
@purintai
Copy link
Author

IN句はOracleだと1000要素までと言う制限があるし、そもそも50万要素あるIN句を投げるのはばかばかしい…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment