2015-05-01 68 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

相关问题