1

I'm in need to fetch over 1000 elements from a Class.

So I tried following advices on this topic, but something is not working correctly, and already spent the whole day to find a solution.

Parse.Cloud.define("getFollow", function(request, response) {
    var following = [];
    var user = request.params.user;
    user.fetch().then(function(result) {
        if (!result.get('following')) {
            following = getFollowing({
                'user': user
            });
        } 
    }).then(function() {    
        response.success(following);
    }, function(error) {
        response.error(error);
    });
});

function getFollowing(request) {
    var count = 0;
    var skip = request.skip || 0;
    var limit = 1000;
    var following = request.following || [];
    var Follow = Parse.Object.extend('follow');
    var query = new Parse.Query(Follow);
    query.limit(limit); 
    query.ascending('objectId');
    query.skip(skip * limit);   
    query.equalTo('followers', request.user);
    query.find().then(function(results) {

        skip+= 1;
        count = results.length;

/* I can't see any DEBUG, seems nothing is queried */

console.log('[DEBUG] Check <count>: ' + count);  


        return Parse.Promise.when(results.map(function(result) {
            following.push(result.get('followed')); 
        }));        
    }).then(function() {            
        if(count >= limit) {
            following = getFollowingUsers({
                'user': request.user,
                'skip': skip,
                'following': following
            });         
        } 
    }).then(function() {    
        return following;
    }, function(error) {
        return error;
    });
}

I tried many variant of this code, trying to return the very first result of the query, rather than a collection. I also tried to remove all contraints, but even so, my query seems not to be run.

I also tried to use a Cloud.code function to make this recursively using only Parse.Cloud, but if I do that, I'm having a message Too many recursive calls into Cloud Code

What did I do wrong with this logic ?

Community
  • 1
  • 1
Toucouleur
  • 1,194
  • 1
  • 10
  • 30

0 Answers0