English 中文(简体)
铁路3:如何归还一部大型的JSON文件
原标题:Rails 3: How to return a big JSON document

我希望在一份JSON文件中归还大约90k件物品,但在我发出呼吁时,我会发现这一错误:

Timeout::Error in ApisController#api_b

time s up!
Rails.root: /root/api_b

我只是用缺电铁路服务器操作“铁路”。

如何使这项工作和归还文件?

增 编

  @bs.each do |a|
          puts "dentro do bs.each"
          @final << {  :Email => a[ headers ][ to ], :At => a[ date ], :subject => a[ headers ][ subject ], :Type => a[ headers ][ status ], :Message_id => a[ headers ][ message_id ] }
        end

- @bs. BSON Object from MongoDB. 具体时间为“@final <<......”

最佳回答

如果你正在经历铁路的停电,并且能够收集数据(例如数据变化经常发生),我将利用resque ,而不是铁路向客户倾斜。 或者,如果数据不能按顺序排列,则使用http://railscasts.com/episodes/222-rack-in-rails-3” rel=“nofollow” Rackhandler,如Sinatra和 Metal,以提出答复。

www.un.org/Depts/DGACM/index_spanish.htm 用于反映样本数据

我得以在3.0.9例铁路中操作以下代码,而Mongo为1.8.4例。 我正在使用Mongo 1.3.1, bson_ext 1.3.1,Webrick 1.3.1和Corr.1.9.2p180x64。 它没有时间,而是需要一些时间来装载。 我的Mongo DB样本有100k记录,没有索引。

before_filter :profile_start
after_filter :profile_end
  def index
    db   = @conn[ sample-dbs ]
    collection = db[ email-test ]

    @final = []
    @bs = collection.find({})
    @bs.each do |a|
      puts "dentro do bs.each"
      @final << {  :Email => a[ headers ][ to ], :At => a[ date ], :subject => a[ headers ][ subject ], :Type => a[ headers ][ status ], :Message_id => a[ headers ][ message_id ] }
    end
    render :json => @final
  end

  private
    def profile_start
      RubyProf.start
    end

    def profile_end
      RubyProf::FlatPrinter.new(RubyProf.stop).print
    end

A more efficient way to dump out the records would be

@bs = collection.find({}, {:fields => ["headers", "date"]})
@final = @bs.map{|a| {:Email => a[ headers ][ to ], :At => a[ date ], :subject => a[ headers ][ subject ], :Type => a[ headers ][ status ], :Message_id => a[ headers ][ message_id ] }}
render :json => @final

My data generator

 100000.times do |i|
   p i
   @coll.insert({:date =>Time.now(),:headers => {"to"=>"me@foo.com", "subject"=>"meeeeeeeeee", "status" => "ffffffffffffffffff", "message_id" => "1234634673"}})
 end
问题回答

暂无回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签