2

我正在使用 Parse 版本“1.14.4”iOS 10.3.2 和 swift 3。无论是本地的(返回的对象是固定的)还是远程的,查询都很慢。谢谢

let placeObject = PFObject(className:"PlaceObject")
let point = PFGeoPoint(latitude:self.PointGlobal.latitude, longitude:self.PointGlobal.longitude)
placeObject["location"] = point
let query = PFQuery(className:"CLocationObject")
// Interested in locations near user.
query.whereKey("location", nearGeoPoint:point)
// Limit what could be a lot of points.
query.limit = 200
let localQuery = (query.copy() as! PFQuery).fromLocalDatastore()

localQuery.findObjectsInBackground{
  (objects: [PFObject]?, error: Error?) -> Void in

self.dataReturnedLocally = true

.....

if self.dataReturnedLocally{
print("local query with no error there was data already")
}

  else {
  print("getting data remotely")
  query.findObjectsInBackground{
    (objects: [PFObject]?, error: Error?) -> Void in
    if error == nil {

      if let objects = objects  {
4

2 回答 2

1

不幸的是,基于地理的查询是 MongoDB 中最慢的查询类型。此外,没有基于位置的自动索引,这使得这些索引特别慢,尤其是对于大型集合。因此,您唯一真正的解决方案是向数据库添加索引以索引位置,并针对您需要进行的位置查询进行优化。尽管请记住其中太多会影响写入速度。

根据您的用例,使用withinMiles而不是nearGeoPoint. 这将返回更少的结果,但也不会花费很长时间来运行。

于 2017-07-13T20:32:30.153 回答
1

LDS 中的所有查询目前都很慢,因为它们没有被索引。LDS 存储了数据的 objectId / JSON 表示,所有过滤都在内存中完成。

于 2017-07-14T13:38:04.023 回答