2015-05-06 47 views
1

我有5K行加上我有一個很長的拉特列,我想添加另一列的位置,並創建一個GeoPoint從長期和拉特,所以我可以做一些GeoLocation從應用程序解析查詢。解析速率限制清洗數據

我已經寫了下面的cloudCode,但是因爲它使用了> 30次/秒的請求而達到了速率限制。我很高興等待1小時完成所有我想要做的事情就是創建一次地理點,然後完成。

Parse.Cloud.define("locationCleanUp", function(request, response) { 

    var setLocation = function(longitude,latitude) { 

     var point = new Parse.GeoPoint({latitude:latitude, longitude:longitude}); 

     //console.log(point); 

     return point; 

    }; 

    var query = new Parse.Query("WeatherSitelistCodes"); 

    query.each(

     function(result) { 

      //console.log(result.get('name')); 
      result.set("location",setLocation(result.get("longitude"),result.get("latitude"))); 
      result.save(); 

     },{ 
      success: function(result) { 
       response.success("All Done!"); 
       //console.log(result.set("location",setLocation(result.get("longitude"),result.get("latitude")))); 

      }, 
      error: function() { 
       console.log("Error: " + error); 
      } 
     }); 
    }); 

任何關於如何做到這一點的提示或建議將不勝感激!

我的下一個停靠港是在本地清理數據,然後上傳,但我走了這麼遠......

+0

這有點痛苦parse.com不提供用於解決這個問題的管理控制檯中的工具,許多人必須具有長和經度,需要轉換爲他們的「GeoLocation」類型。 – isa56k

回答

2

它那種很爛的解析不提供任何幫助這和解決方案吮吸他們爲現場等待循環,如:

function sleep(milliseconds) { 
    var start = new Date().getTime(); 
    for (var i = 0; i < 1e7; i++) { 
    if ((new Date().getTime() - start) > milliseconds) { 
     break; 
    } 
    } 
} 

後各保存到整體吞吐量限制,你會打電話。

+1

我不認爲這會起作用。 Parse.com表示雲功能將在掛鐘時間15秒後終止。根據我的理解,完成這項工作的唯一方法是運行計劃任務,查找OP想要更改的條件,並將其更改爲小卡盤(例如,每次1k行)。要麼是這樣,要麼使用這種或某種技術來扼殺客戶。 – danh

+0

@danh好點,它應該確實作爲一個工作運行,然後它將有15分鐘的運行時間(作業可以手動運行,也可以按計劃) – Wain

+0

謝謝,都指出我在正確的方向..我在下面做了什麼... – isa56k

1

謝謝danh和Wain。

我最終使用後臺作業每5分鐘運行一次,查詢updatedAt日期以獲取比今天更少的記錄。

// Use Parse.Cloud.define to define as many cloud functions as you want. 
// For example: 
Parse.Cloud.job("locationCleanUp", function(request, response) { 

    var setLocation = function(longitude,latitude) { 

     var point = new Parse.GeoPoint({latitude:latitude, longitude:longitude}); 

     console.log(point); 

     return point; 

    }; 

    var date = new Date("2015-05-08"); 
    var site = Parse.Object.extend("WeatherSitelistCodes"); 
    var query = new Parse.Query("WeatherSitelistCodes"); 
    query.lessThan("updatedAt",date); 

    query.each(

     function(result) { 
      var lat = parseFloat(result.get("latitude")); 
      var longi = parseFloat(result.get("longitude")); 
      var newLocation = setLocation(longi,lat); 
      var location = JSON.stringify(result.get("location")); 

      console.log("Location: " + result.get("name")); 

       result.save({ 
        location: newLocation 
       },{ 
        success: function(result) { 
         console.log("Saved!"); 

        }, 

        error: function(result, error) { 
         console.log("Error" + error.message); 
        } 
       }); 

      },{ 
      success: function() { 
      // results is an array of Parse.Object. 
      console.log('Done!'); 
      response.success("Updated Records!!"); 
       }, 
      error: function(error) { 
      // error is an instance of Parse.Error. 
      console.log('Error: +' error.message); 
      response.error("Failed to save vote. Error=" + error.message); 
      } 
     }); 
});