【发布时间】:2015-05-01 23:09:53
【问题描述】:
我在最新的 Parse javascript SDK (v 1.4.2) 中发现了一个错误,该错误 Parse.Query.each() 似乎并没有通过所有匹配的记录。它似乎在某个时间点后停止了。
我有一个存储用户位置 GeoPoints 的 UserLocation 类(在“geo”列中)。我正在尝试查找与场地位置的距离小于 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 条记录,更不用说效率较低了。
这似乎与 Parse javascript 文档说 Parse.Query.each() 没有限制相矛盾。有人遇到过同样的问题吗?
【问题讨论】: