我有一个应用程序可以检索特定半径范围内的用户数组(使用GeoFire)但是,如果这些用户不适用,我的应用程序需要解雇这些用户。因此,我现在有两个数组。
数组(1)半径范围内的用户
已被解雇的数组(2)用户
我的问题,对于长篇大论而言,遗憾的是从(1)中删除Array(2)的最有效方法是什么?因为两个阵列都可以有数百个项目。如果我过滤数组,这肯定是一个低效率的&获得最终数组的方式很慢。
当我偶然发现一些Firebase数据库规则示例时,我确实有一个灯泡时刻。我是否可以在Firebase数据库中创建一个包含所有不适用用户的子项,然后让规则将它们作为"!= .read"?
通过关于规则的文档,它指出规则不是过滤器。但是,我没有看到任何有效的过滤阵列的方法。
一如往常任何帮助表示赞赏。
添加当前数据结构:
{
"not_applicable" : {
"yhgeZLXJhuXKmbnK1eRwkC4xmO83" : {
"yhgeZLXJhuXKmbnK1eRwkC4xmO84" : "",
"yhgeZLXJhuXKmbnK1eRwkC4xmO85" : "",
"yhgeZLXJhuXKmbnK1eRwkC4xmO87" : "",
"yhgeZLXJhuXKmbnK1eRwkC4xmO88" : "",
"yhgeZLXJhuXKmbnK1eRwkC4xmO89" : "",
"yhgeZLXJhuXKmbnK1eRwkC4xmO90" : ""
}
},
"locations" : {
"yhgeZLXJhuXKmbnK1eRwkC4xmO83" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -122.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO84" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -102.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO85" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33141, -122.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO86" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, "-38.2333" ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO87" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -132.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO88" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -122.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO89" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -122.0312186 ]
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO90" : {
".priority" : "9q9hrh5sdd",
"g" : "9q9hrh5sdd",
"l" : [ 37.33233141, -122.0312186 ]
}
},
"users" : {
"yhgeZLXJhuXKmbnK1eRwkC4xmO83" : {
"email" : “someEmail”,
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO84" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO85" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO86" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO87" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO88" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO89" : {
"email" : "someEmail",
},
"yhgeZLXJhuXKmbnK1eRwkC4xmO90" : {
"email" : "someEmail",
}
}
}
我以用户身份登录" yhgeZLXJhuXKmbnK1eRwkC4xmO83"我在geoFire中运行.keyEntered查询,如下所示。
func runQuery(location: CLLocation) {
let query = geoFire?.query(at: location, withRadius: Double(2000))
query?.observe(.keyEntered, with: { (key:String!, location: CLLocation!) in
self.getResults(key: key)
})
query?.observeReady({
//MARK: - geoFire Query Observe Ready Something Missing Here :(
print("Observe geoFire Ready")
})
}
我获取这些密钥并使用self.getResults(key:key)搜索数据库中的用户,如下所示
private func getResults(key: String!) {
userRef.child(key).observeSingleEvent(of: .value, with: { (snapshot) in
let snapshotResult = snapshot.value as? [String:AnyObject]
let userProfileURL = snapshotResult?["profileURL"] as! String
let userName = snapshotResult?["name"] as! String
let uid = snapshot.ref.key
let aRequest = UserResults(userName: userName,
userProfileURL: userProfileURL,
uid: uid)
self.userResults.append(aRequest)
self.filteredUserResults = self.userResults.filter {
$0.uid != self.userID
}
})
}
但是,一旦用户确定用户结果不适用,它就不能回到结果中。它必须在某处引用。即,如上所述,在Array(2)中。