title: Working with performance on requests Parse SDK
body: <p>I'm having some performance issues with my Parse queries, using Parse SDK.</p>
  
  <p>On some requests, I have to get a ressources related to another one. E.g. :</p>
  
  <ul>
  <li>I get all elements from ClassA</li>
  <li>foreach ClassA elements, I have to find all ClassB and ClassC elements which contain a pointer to the relevant entry in ClassA.</li>
  </ul>
  
  <p>Right now, to sum up:</p>
  
  <ul>
  <li>I query all my ClassA elements</li>
  <li>I loop on the results, and create a Promise (Parse query) to get ClassB elements and another one (Parse query) to get ClassC elements foreach result</li>
  </ul>
  
  <p>My issue is that solution makes a lot of Parse Query, so a lot of Promise that I have to wait for. <strong>The real issue is that on my local env, all is working fine, the whole request makes 1s or less</strong> (it's quite heavy, but it does 45 parse query in the current case - based on my Class entries).
  <strong>On my production server, same code, same data, same Node version, the same request makes 30s or more (=> timeout)</strong>.</p>
  
  <p>This is the relevant part of the code (it's old and messy) :</p>
  
  <pre><code>router.get('/:userId/company/customers', (req, res, next) =&gt; {
    if('company' in req.jwtData.data) {
      const company = req.jwtData.data.company;
      const query = new Parse.Query('Cards');
      const Companies = Parse.Object.extend('Companies');
      const currentCompany = new Companies({id: company.objectId});
      query.equalTo('company', currentCompany).find().then((cards) =&gt; {
        if(cards.length){
          const customersArrayId = cards.map(card =&gt; card.toJSON().user.objectId);
          const usersQuery = new Parse.Query('_User').containedIn('objectId', customersArrayId).find({ useMasterKey: true });
          usersQuery.then(customersResponse =&gt; {
            const customers = [];
            const customersPromises = [];
            if(customersResponse.length) {
              for (let index = 0; index &lt; customersResponse.length; index++) {
                let customer = {
                  ...customersResponse[index].toJSON(),
                  ...customersResponse[index].attributes
                }; 
                const customerPromises = [];
                const customerId = customer.objectId;
                const stamps = new Parse.Query('Stamps').equalTo('user', new UserModel({objectId: customerId})).equalTo('company', currentCompany).limit(CONSTANTS.QUERY_MAX_LIMIT).find().then((stamps) =&gt; {
                  return stamps;
                }).catch(error =&gt; {
                  res.json({
                    success: false,
                    error
                  });
                });
                const cards = new Parse.Query('Cards').equalTo('user', new UserModel({objectId: customerId})).equalTo('company', currentCompany).limit(CONSTANTS.QUERY_MAX_LIMIT).find().then((cards) =&gt; {
                  return cards;
                }).catch(error =&gt; {
                  res.json({
                    success: false,
                    error
                  });
                });
                customers.push(customer);
                customerPromises.push(stamps);
                customerPromises.push(cards);
                customersPromises.push(customerPromises);
              }
              if(customersPromises.length) {
                const allPromises = customersPromises.map(customerP =&gt; Promise.all(customerP));
                Promise.all(allPromises).then((customerPromiseResponses) =&gt; {  
                  console.log('allPromises done, mapping all users data...');
                  for (let index = 0; index &lt; customerPromiseResponses.length; index++) {                  
                    const customerResponseData = customerPromiseResponses[index];
                    const stamps = customerResponseData[0];
                    const cards = customerResponseData[1];
                    const companyEmailAllowed = () =&gt; {
                      let check = false;
                      if(customers[index].hasOwnProperty('companiesNewsletterAgreements')) {
                        check = customers[index].companiesNewsletterAgreements.indexOf(company.objectId) &gt; -1;
                      }
                      return check;
                    };
                    customers[index] = {
                      ...customers[index],
                      email: companyEmailAllowed() ? customers[index].email : null,
                      stamps,
                      cards,
                    }
                  }                
                  res.json({
                    success: true,
                    data: customers
                  });
                }).catch(error =&gt; {
                  res.json({
                    success: false,
                    error
                  });
                });
              }
              else {
                res.json({
                  success: true,
                  data: customers
                });
              }
  
            } else {
              res.json({
                success: true,
                data: customers
              });
            }
  
  
  
          });
        } else {
          res.json({
            success: true,
            data: []
          });
        }
  
  
      });
    } else {
      res.json({
        success: false,
        error: "No company found."
      });
    }
  });
  </code></pre>
  
  <p><strong>My question is: is it possible to get the same data in a more performant way (less Parse queries, less Promises)?</strong> </p>