2015-05-01 65 views
3

我已經看到最新的Parse JavaScript SDK(v 1.4.2)中的一個錯誤 Parse.Query.each()似乎並沒有去所有的匹配記錄。似乎在某個點之後停止了。Parse.Query.each()不包括所有記錄

我有一個UserLocation類存儲用戶位置GeoPoints(在列「地理」)。我試圖找到距離場地位置不到10英里的用戶位置列表。當我明白Parse.Query.find()具有1000的限制。根據這個帖子,Parse.Query.each()沒有這樣的限制: https://parse.com/questions/pfquery-setskip-does-not-skip-beyond-10000

但是,這似乎並沒有被從我的測試結果判斷:

mylocation.get("deviceId") 
"fa72f38bc0af44f090824a38fd1963b4" 
venueGeo.milesTo(mylocation.get("geo")); 
2.1965871191375173 

正如你所看到的,我的位置距離會場地點約2英里。但是,如果我跑10英里的距離查詢,結果沒有我的位置:

var locationQuery = new Parse.Query("UserLocation").withinMiles("geo", venueGeo, 10); 
results = [] ; 
locationQuery.each(function(location) {results.push(location.get("deviceId"))}) 
b.Promise {_resolved: false, _rejected: false, _resolvedCallbacks: Array[0], _rejectedCallbacks: Array[0], resolve: function…} 
results.length 
107 
results.indexOf("fa72f38bc0af44f090824a38fd1963b4") 
-1 

但如果我增加額外的約束來查詢返回其DEVICEID等於我的位置的設備它記錄。 Parse.Query.each()實際上包含它。我想像新的查詢將只返回以前的查詢的子集。但它實際上返回這不是在前面的查詢記錄:

var locationQuery = new Parse.Query("UserLocation").withinMiles("geo", venueGeo, 10).equalTo("deviceId", "fa72f38bc0af44f090824a38fd1963b4"); 
results = [] ; 
locationQuery.each(function(location) {results.push(location.get("deviceId"))}) 
b.Promise {_resolved: false, _rejected: false, _resolvedCallbacks: Array[0], _rejectedCallbacks: Array[0], resolve: function…} 
results.length 
1 
results.indexOf("fa72f38bc0af44f090824a38fd1963b4") 
0 

如果通過使用Parse.Query.limit(1000)和Parse.Query.skip()記錄本人資料頁,我終於找到了我的紀錄8

locationQuery.skip(7000) 
locationQuery.find().then(function(locations){ 
    results = locations.map(function(location){ 
    return location.get("deviceId"); 
    }) 
}) 
results.indexOf("fa72f38bc0af44f090824a38fd1963b4") 
-1 

locationQuery.skip(8000) 
locationQuery.find().then(function(locations){ 
    results = locations.map(function(location){ 
    return location.get("deviceId"); 
    }) 
}) 
results.indexOf("fa72f38bc0af44f090824a38fd1963b4") 

927 

頁,但頁面有其自身的侷限性,因爲你不能跳過超過10000條記錄,更何況它的效率較低。

這似乎矛盾的是,解析JavaScript文檔說Parse.Query.each()沒有限制。有沒有人遇到同樣的問題?

回答

0

我沒有在文檔中看到我們被告知每個()不受1k限制,但它是不合理的。發佈的代碼顯示對我來說,呼叫和回覆可能會受到競爭條件的影響,也就是說,在衡量結果時,每個承諾可能不會實現。這是一個確定性測試,可能很好找到該記錄:

var locationQuery = new Parse.Query("UserLocation"); 
locationQuery.withinMiles("geo", venueGeo, 10); 
results = []; 
locationQuery.each(function(location { 
    results.push(location.get("deviceId")); 
}).then(function() { 
    console.log("results length=" + results.length); 
    console.log("index of target device id=" + results.indexOf("fa72f38bc0af44f090824a38fd1963b4")); 
}); 
+0

感謝您的答覆。我的印象是,Parse.Query.each()並沒有通過閱讀這個[post](https://parse.com/questions/paging-through-more-than-10000-results) 來強加一個上限「Parse.Query.each()它可以讓你獲取每個匹配查詢的對象,而且沒有上限。」 我上面粘貼的代碼來自Chrome的JavaScript控制檯。在我真正的node.js代碼中,我確實有「then」塊「流動」每個「: 'return locationQuery.each(function(location){ filteredLocations.push(location); })。then(function ){ return filteredLocations; });' – dopamine

+0

嗯。 Hector給出了很多很好的答案,所以我想這是一個沒有記錄的特性,forEach沒有上限。鑑於此(並且您正在按順序運行您的查詢),它確定似乎您找到了一個合法的錯誤。我敢打賭,如果你報告它,他們會很感激......一種解決方法是用'find()'通過'skip()'分頁來運行查詢。我應該編輯我的答案來說明,還是你知道該怎麼做? – danh

+0

我提交了一個錯誤: https://developers.facebook。com/bug/103854869948544/ 看起來問題只發生在查詢涉及GeoPoint時。 跳過有其自己的限制(不能跳過超過10000)。所以這對我也不起作用。我確實嘗試了Hector使用orderBy + limit + skip的建議。這對我來說也不起作用(至少還沒有,仍然在調試)。最初的印象是,在檢索記錄之後應用orderBy,而不是在應用約束之前應用orderBy結果作爲下一批次的分隔符不起作用。 – dopamine

相關問題