Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created January 5, 2023 13:09
Show Gist options
  • Save equivalent/06977eb934b04e4a5f7f5304a3c40d6d to your computer and use it in GitHub Desktop.
Save equivalent/06977eb934b04e4a5f7f5304a3c40d6d to your computer and use it in GitHub Desktop.
how to generare CSV for milion records in sidekiq
Model.pluck(:id, :name, ...).find_in_batches(10_000) do |ary|
CSV.open("tmp.csv", "ab") do |csv|
csv << ary.map{|a| a.join ','}.join("\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment