title: What would cause "Request timed out" in parse.com cloud code count?
body: <p>One of my cloud functions is timing out occasionally. It seems to have trouble with counting, although there are only around 700 objects in the class. I would appreciate any tips on how to debug this issue.</p>
  
  <p>The cloud function works correctly most of the time.</p>
  
  <p>Example error logged:</p>
  
  <pre><code>E2015-02-03T02:21:41.410Z] v199: Ran cloud function GetPlayerWorldLevelRank for user xl8YjQElLO with:
    Input: {"levelID":60}
    Failed with: PlayerWorldLevelRank first count error: Request timed out
  </code></pre>
  
  <p>Is there anything that looks odd in the code below? The time out error is usually thrown in the second count (query3), although sometimes it times out in the first count (query2).</p>
  
  <pre><code>Parse.Cloud.define("GetPlayerWorldLevelRank", function(request, response) {    
      var query = new Parse.Query("LevelRecords");
      query.equalTo("owner", request.user);
      query.equalTo("levelID", request.params.levelID);
      query.first().then(function(levelRecord) {
          if (levelRecord === undefined) {
              response.success(null);
          }
          // if player has a record, work out his ranking
          else {
              var query2 = new Parse.Query("LevelRecords");
              query2.equalTo("levelID", request.params.levelID);
              query2.lessThan("timeSeconds", levelRecord.get("timeSeconds"));
              query2.count({
                  success: function(countOne) {
                      var numPlayersRankedHigher = countOne;
  
                      var query3 = new Parse.Query("LevelRecords");
                      query3.equalTo("levelID", request.params.levelID);
                      query3.equalTo("timeSeconds", levelRecord.get("timeSeconds"));
                      query3.lessThan("bestTimeUpdatedAt", levelRecord.get("bestTimeUpdatedAt"));
                      query3.count({
                          success: function(countTwo) {
                              numPlayersRankedHigher += countTwo;
                              var playerRanking = numPlayersRankedHigher + 1;                    
                              levelRecord.set("rank", playerRanking);
                              // The SDK doesn't allow an object that has been changed to be serialized into a response.
                              // This would disable the check and allow you to return the modified object.
                              levelRecord.dirty = function() { return false; };    
                              response.success(levelRecord);    
                          },
                          error: function(error) {
                              response.error("PlayerWorldLevelRank second count error: " + error.message);
                          }                            
                      });
                  },
                  error: function(error) {
                      response.error("PlayerWorldLevelRank first count error: " + error.message);
                  }
              });
           }
      });
  });
  </code></pre>