Created
July 1, 2013 20:16
-
-
Save MiguelCarranza/5904182 to your computer and use it in GitHub Desktop.
Get all the objects stored in Parse. Hack for breaking the limit of 1000 results per request when using the free version of parse.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get all the objects stored in Parse. Hack for breaking the | |
* limit of 1000 results. | |
*/ | |
if (Parse.Query.prototype.findAll == null) | |
Parse.Query.prototype.findAll = function (a) { | |
var res = [], | |
countQuery, numRequests, requestsLeft, | |
parseResultLimit = 1000, | |
_this = this; | |
function partialQuery (skip) { | |
var query; | |
query = new Parse.Query(_this.className); | |
query.skip(skip); | |
query.limit(parseResultLimit); | |
query.find({ | |
success: function (models) { | |
res = res.concat(models); | |
requestsLeft --; | |
if (requestsLeft == 0) { | |
a.success(res); | |
} | |
} | |
}); | |
} | |
countQuery = new Parse.Query(this.className); | |
countQuery.count({ | |
success: function (count) { | |
numRequests = Math.ceil(count / parseResultLimit); | |
requestsLeft = numRequests; | |
if (count == 0) { | |
a.success([]); | |
} | |
for (var i = 0; i < numRequests; i++) { | |
partialQuery(i * parseResultLimit); | |
} | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment