2014-12-13 55 views
0

我有一个云编写的代码Parse.com会考虑多少个API请求?

Parse.Cloud.define("getApartmentVendorProduct", function(request, response) { 
    var isApartmentCallComplete = false; 
    var isVendorCallComplete = false; 
    var isProductCallComplete = false; 

    var result = {}; 

    var apartmentQuery = new Parse.Query("Apartment"); 
    apartmentQuery.find({ 
    success: function(results) { 
     isApartmentCallComplete = true; 
     results.apartments = results; 
    } 
    }); 

    var vendorQuery = new Parse.Query("Vendor"); 
    vendorQuery.find({ 
    success: function(results) { 
     isVendorCallComplete = true; 
     results.vendors = results; 
    } 
    }); 

    var productQuery = new Parse.Query("Product"); 
    productQuery.find({ 
    success: function(results) { 
     isProductCallComplete = true; 
     results.products = results; 
    } 
    }); 

    setInterval(function() { 
    if (isApartmentCallComplete && isVendorCallComplete && isProductCallComplete) { 
     response.success(results); 
    } 
    }, 50); 

}); 

PS:我很清楚地知道,在setInterval的解析不会工作。这个代码仅仅是理解。

在这个云功能,我正在做3查询操作。

从我的Android应用我打电话这个云代码。

这里是我的问题。 这个考虑了多少个API请求?通过云代码和由Android制成1项API请求作出

1)3 API请求 - 共计4

2)由Android制成仅有1 API请求。 - 总计1

+1

应该选择1.你可以检查'阿比Requests'这在应用程序的分析仪表板。 – eth3lbert 2014-12-15 00:17:06

+0

感谢和是的选项是1我会发布我试过的代码 – 2014-12-15 05:33:46

回答

0

的选项1它使4个请求。

我试着用示例代码测试脉冲限

Parse.Cloud.define("testBurstLimit", function(request, response) { 
    var globalI = 0; 
    for(var i = 0; i < 500; i++) { 
    var productQuery = new Parse.Query("Product"); 
    productQuery.find({ 
     success: function(results) { 
     console.log("success " + i + " " + globalI); 
     globalI++; 
     if (globalI == 250) { 
      response.success("success"); 
     } 
     }, 
     error: function(error) { 
     isApartmentCallComplete = true; 
     if (isApartmentCallComplete && isVendorCallComplete && isProductCallComplete) { 
      console.log(error.message + " " + error.code); 
     } 
     } 
    }); 
    } 
}); 

一件事怪我注意到的是。解析不会计算每秒请求数,而是以每秒/每分钟请求数计算。检查从解析响应时,我一次又一次地执行BurstLimit云代码

{"code":155,"error":"This application performed 1814 requests over the last 28s, and exceeded its request limit. Please retry in 32s"}