I have an android application I am trying to sync with a rails app.
In the android app I download and load a json object from the server (using an OAuth token for authentication):
private JSONArray getJSON(URL url, String authToken) throws IOException, JSONException {
URLConnection con = url.openConnection();
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + authToken);
InputStream is = new BufferedInputStream(con.getInputStream());
Scanner s = new Scanner(is).useDelimiter("\\A");
String text = s.hasNext() ? s.next() : "";
return new JSONArray(text);
}
I'm trying to reload the existing data and it is ~380k. When I run the code I get the following in the rails server log:
Started GET "/events.json?created_since=0" for 192.168.1.111 at 2014-01-22 20:15:16 -0500
Processing by EventsController#index as JSON
Parameters: {"created_since"=>"0", "event"=>{}}
Doorkeeper::AccessToken Load (0.6ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = [:filtered:] ORDER BY "oauth_access_tokens"."id" ASC LIMIT 1
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 501661262]]
Habit Load (0.7ms) SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ? ORDER BY "habits"."id" ASC LIMIT 1000 [["user_id", 501661262]]
Event Load (26.7ms) SELECT "events".* FROM "events" WHERE "events"."habit_id" = ? [["habit_id", 1]]
⋮
Rendered events/index.json.jbuilder (3422.5ms)
Completed 200 OK in 4491ms (Views: 3436.2ms | ActiveRecord: 73.4ms)
[2014-01-22 20:15:21] ERROR Errno::ECONNRESET: Connection reset by peer
/home/will/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `eof?'
/home/will/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `run'
/home/will/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
The connection reset is repeated seven times. The client receives about 260k of data. app/views/events/index.json.jbuilder
is:
json.array!(@events) do |event|
json.extract! event, :id, :habit_id, :time, :description
end
The same method is used to load a different model with only a few entries and it loads correctly. Is there a limit to how big a file can be downloaded? In any case pagination seems like a good idea. Anyone know of any guidelines on what size chunks I ought to break it up into?