0
の投稿が好きかどうかを効率的に判断するユーザーが投稿を好きな場所にアプリを持っていて、現在のユーザーが過去に効率的に投稿を好きだったかどうかを判断したい。私のデータは現在、次のようになります。しかしFirebase
if let people = post["peopleWhoLike"] as? [String: AnyObject] {
if people[(Auth.auth().currentUser?.uid)!] != nil {
posst.userLiked = true
}
}
:
また、私はこれをやっている私の現在のクエリで
すべてのユーザーのための好みを保存します私は、これは非常に効率的ではない投稿のすべての好きなものをダウンロードする必要があると私は信じて、これを試した:
if (post["peopleWhoLike\(Auth.auth().currentUser!.uid)"] as? [String: AnyObject]) != nil {
posst.userLiked = true
}
2番目の方法は正しく動作していないようです。これを行うより良い方法はありますか?
pagingReference.child("posts").queryLimited(toLast: 5).observeSingleEvent(of: .value, with: { snap in
for child in snap.children {
let child = child as? DataSnapshot
if let post = child?.value as? [String: AnyObject] {
let posst = Post()
if let author = post["author"] as? String, let pathToImage = post["pathToImage"] as? String, let postID = post["postID"] as? String, let postDescription = post["postDescription"] as? String, let timestamp = post["timestamp"] as? Double, let category = post["category"] as? String, let table = post["group"] as? String, let userID = post["userID"] as? String, let numberOfComments = post["numberOfComments"] as? Int, let region = post["region"] as? String, let numLikes = post["likes"] as? Int {
、これをチェックアウト:https://www.youtube.com/watch?v=HjlQH3RsGcUの真ん中にビデオフランクはそれについて何か言います。 https://stackoverflow.com/questions/41527058/many-to-many-relationship-in-firebaseはおそらくあなたが使用できるものです。私はより迅速にクエリするためにあなたのデータベースを非正規化すべきだと思います。はい、この方法で重複データを取得します。 –
そのようなデータが投稿とuserActivityに保存されているため、データは既に非正規化されています... – DoesData