0

I am trying to export a table which has over 100,000 rows

def export  
  export_data = []
  MyModel.uncached do
    MyModel.find_each do |s|
      export_data << {
        :col1 => s.col1,
        :col2 => s.col2,
        :col3 => s.col3,
        :col4 => s.col4
      }
    end
  end
  export_data = {:export_data => export_data }
  send_data export_data.to_json, :type => :json, :disposition => "attachment", :filename => "export_data.json"
end

When I hit this action using a url_path it is taking very long time to process the request and also the file downloaded is around 80MB.

What is the proper way to approach this problem so that the user need not wait for the request to complete?

SAGAR TALLA
  • 375
  • 4
  • 12

1 Answers1

0
  1. Make raw sql query: Rails raw SQL example
  2. Convert returned value to json.

Another way is tools like this. Just google something similar

Community
  • 1
  • 1
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142