Skip to content

Instantly share code, notes, and snippets.

@bradleypriest
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradleypriest/9561408 to your computer and use it in GitHub Desktop.
Save bradleypriest/9561408 to your computer and use it in GitHub Desktop.
FindManyInChunks
function flatten(arrays) {
return Array.prototype.concat.apply([], arrays)
}
findMany: function(store, type, ids) {
var chunkSize = 200;
if (ids.length > chunkSize) {
var promises = [],
index = 0,
currentIds;
while (index < ids.length) {
currentIds = ids.slice(index, index + chunkSize);
promises.push(this._super(store, type, currentIds));
index += chunkSize;
}
return Ember.RSVP.all(promises).then(function(responses) {
var mergedResponse = {};
Ember.keys(responses[0]).filter(function(key) {
return responses[0][key] instanceof Array;
}).forEach(function(key) {
mergedResponse[key] = flatten(responses.mapBy(key));
});
return mergedResponse;
});
} else {
return this._super(store, type, ids)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment