AngularJS HTTP call takes two minutes while Rails action takes 20 seconds, how can I debug it?

I have an AngularJS app and there is one page in my app, only one, it takes 2 minutes to load. It loads a bit of data, but the data itself is only 700KB and I was comparing all rails actions from start to render and only takes 15-20 seconds. But when I look at the actual network call, or I put a timer in front of the angular http post call and then one of them, they both show that the call takes almost 2 minutes. I cannot figure out what is going on between rendering and success in angular what will be causing this extreme time difference. Does anyone know how I could debug this or perhaps know what might be causing this?

The rails action just does some big database queries, everything is optimized, then does some work on the data, then the data (which is already JSONified with to_json) is output.

Rails ends with Completed 200 OK in 20458ms (Views: 913.8ms | ActiveRecord: 139.6ms)

Edit: If I limit my data, it's almost instantaneous, so it's definitely data-related. But I'm not sure what can cause a minute and a half gap between when the rails action is over and the success of the http post.

Edit2: The ajax call takes an equal amount of time. So there must be a problem with how the data is parsed on the front, not sure what is the best way to do it. Because there is an obvious problem between the render and the page.

+3


source to share


1 answer


It turns out the problem was somehow an extremely complex hash that an old colleague of mine wrote. I think this was all pretty unnecessary, so I removed all 90 lines of code where he built a hash from scratch and 3 lines instead.



Now I have two activerecord requests with correct inclusions and then wrote one render state for those activerecord objects as_json

with correct include and only parameters and the only one that now loads after 25 seconds in development. I can only imagine it would be faster in production / staging. I don't know why hashes are so hard to render as json, but calling as_json

on active objects the record inside the render statement fixed my problem completely.

0


source







All Articles