0

我正在 Rails 应用程序中对我的索引操作运行查询,如果您查看日志,它会非常快:

Started GET "/apartments?within=-74.01798248291016%2C40.746346606483826%2C-73.8943862915039%2C40.79314877043915&per_page=500" for 127.0.0.1 at 2012-11-01 16:58:21 +0200
Processing by ApartmentsController#index as JSON
  Parameters: {"within"=>"-74.01798248291016,40.746346606483826,-73.8943862915039,40.79314877043915", "per_page"=>"500"}
MONGODB (228ms) development['$cmd'].find({"count"=>"apartments", "query"=>{:status=>"available", :coordinates=>{"$within"=>{"$box"=>[[-74.01798248291016, 40.746346606483826], [-73.8943862915039, 40.79314877043915]]}}}, "fields"=>{:neighborhood_id=>0}}).limit(-1)
MONGODB (445ms) development['apartments'].find({:status=>"available", :coordinates=>{"$within"=>{"$box"=>[[-74.01798248291016, 40.746346606483826], [-73.8943862915039, 40.79314877043915]]}}}, {:neighborhood_id=>0}).limit(500).sort([[:qs, :desc]])
Completed 200 OK in 9737ms (Views: 8816.0ms)

如果数据库查询只需要 445 毫秒,为什么 JSON 需要将近 10 秒来呈现并通过网络发送回?

有没有更快的方法将@apartments集合呈现为 JSON?

4

1 回答 1

0

使用不同的 JSON 序列化程序?

https://rubygems.org/gems/oj

于 2012-11-01T15:12:46.877 回答