Добавление индекса в правила Firebase
Я запрашиваю данные из Firebase на основе текущего местоположения пользователя, используя GeoFire. Я получаю:
Использование неуказанного индекса. Для повышения производительности рассмотрите возможность добавления ".indexOn": "g" в / к вашим правилам безопасности.
в консоли. Ниже мой код запроса:
ref = Database.database().reference()
let geoFire = GeoFire(firebaseRef: ref)
let center = CLLocation(latitude: (userLocation.coordinate.latitude), longitude: (userLocation.coordinate.longitude))
let circleQuery = geoFire?.query(at: center, withRadius: 1)
circleQuery?.observe(.keyEntered, with: { key, location in
guard let key = key else { return }
geoFire?.getLocationForKey(key, withCallback: { (location, error) in
let myAnnotation: MKPointAnnotation = MKPointAnnotation()
myAnnotation.coordinate = CLLocationCoordinate2DMake((location?.coordinate.latitude)!, (location?.coordinate.longitude)!);
self.currentLocationMapView.addAnnotation(myAnnotation)
})
self.ref.child("services").child(key).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
let servicename = value?["name"] as? String ?? ""
let address = value?["address"] as? String ?? ""
self.nameArray.append(servicename)
self.addressArray.append(address)
if (self.nameArray.count > 0) {
self.customTableView.reloadData();
}
})
})
Моя вкладка правил Firebase имеет следующие настройки.
"rules": {
".read": true,
".write": "auth != null"
}
Независимо от того, куда я вставляю ".indexOn": "g", я получаю ошибку и не могу сохранить правила. Любая помощь?
1 ответ
Документация указывает на примеры.
"rules": {
".read": true,
".write": "auth != null",
".indexOn": ["g"]
}