2014-12-13 58 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"}