如果我要订购的节点都具有相同的值,则无法获取分页的内容?

问题描述

我正在尝试按ranking降序获取数据(帖子)。当其他用户与帖子互动时,更改此排名。最初发布该帖子时,其起始排名为0.0

问题

当前正在发生什么: 目前,我按排名以DESC顺序获取我的第一批10条帖子,但是当我到达10的末尾而不是获取下一批10条帖子时,它什么也不会获取

我该如何解决?我还需要包括所有0.0排名的内容


代码

重要部分:

一个电话:

                            ref.child("Hashtags").child(currentHashtag).child("posts")//ref.child("Timeline").child((Auth.auth().currentUser?.uid)!)
                            .queryOrdered(byChild: queryOrderdBy)
                            .queryLimited(toLast: 10)
                            .observeSingleEvent(of: .value,with: { (snapshot) in

呼叫通话:

                            let lastRanking = (postArray.last!.interimMedia.first!.ranking)
                        let postRef = ref.child("Hashtags").child(currentHashtag).child("posts")
                        postRef.queryOrdered(byChild: queryOrderdBy)
                            .queryEnding(atValue: lastRanking)
                            .queryLimited(toLast: UInt(limit))//10
                            .observeSingleEvent(of: .value,with: { (snapshot) in

        func getRecentExplorePosts(limit: Int,wasCalledOnP3: Bool) {
                let ref = Database.database().reference()
                
        //        if GlobalSharedData.shared.isOnFollowingOption {
                    if postArray.count == 0 {
                        ref.child("Hashtags").child(currentHashtag).child("posts")//ref.child("Timeline").child((Auth.auth().currentUser?.uid)!)
                            .queryOrdered(byChild: queryOrderdBy)
                            .queryLimited(toLast: 10)
                            .observeSingleEvent(of: .value,with: { (snapshot) in
                                
                                self.totalItems = snapshot.children.allObjects.count
                                //var i = 0
                                for case let child as DataSnapshot in snapshot.children.reversed() {//.reversed()
                                    var runAll = true
                                    let keyvalue = child.key
                                    let uid = keyvalue.split(separator: ":")[0]
                                    let postIDDoubleVal = keyvalue.split(separator: ":")[1]
                                    
                                    let timelineTimestamp = child.childSnapshot(forPath: "timeStamp").value as! Double
                                    if (nil == child.childSnapshot(forPath: "ranking").value as? Double) {
                                        print("fldjsahajasdhfkdsahfjdashfjksdahfjksda")
                                        self.totalItems-=1
                                        if snapshot.children.allObjects.count == 0 || self.totalItems == 0 {
                                            self.hasFetched = true
                                            self.postsCollectionView.reloadData()
                                            self.refreshControl.endRefreshing()
                                            self.postsCollectionView.isUserInteractionEnabled = true

                                        } else if self.totalItems == self.postArray.count {
                                            self.hasFetched = true
                                            self.postsCollectionView.reloadData()
                                            self.refreshControl.endRefreshing()
                                            self.postsCollectionView.isUserInteractionEnabled = true

                                        }
                                        //break;
                                        runAll = false
                                    }
                                    if runAll {
                                        let timelineRanking = child.childSnapshot(forPath: "ranking").value as! Double
                                        self.fetchUsersPost(uid: "\(uid)",postID: "post:\(postIDDoubleVal)",timelineTimeStamp: timelineTimestamp) { post in
                                            if post != nil {
                                                post?.interimMedia.first?.ranking = timelineRanking
                                                self.postArray.append(post!)
                                                
                                                if self.totalItems == self.postArray.count {
                                                    self.hasFetched = true//snapshot.children.allObjects.count > 0
                                                    
                                                    self.postsCollectionView.reloadData()
                                                    self.refreshControl.endRefreshing()
                                                    self.postsCollectionView.isUserInteractionEnabled = true
                                                }
                                            } else {
                                                
                                                print("ffdasfdasfdsafadsksdafjkhdsad")
                                                self.totalItems-=1
                                                if snapshot.children.allObjects.count == 0 || self.totalItems == 0 {
                                                    self.hasFetched = true
                                                    self.postsCollectionView.reloadData()
                                                    self.refreshControl.endRefreshing()
                                                    self.postsCollectionView.isUserInteractionEnabled = true

                                                } else if self.totalItems == self.postArray.count {
                                                    self.hasFetched = true
                                                    self.postsCollectionView.reloadData()
                                                    self.refreshControl.endRefreshing()
                                                    self.postsCollectionView.isUserInteractionEnabled = true

                                                }
                                            }
                                        }
                                    }
                                }
                                if snapshot.children.allObjects.count == 0 || self.totalItems == 0 {
                                    self.hasFetched = true
                                    self.postsCollectionView.reloadData()
                                    self.refreshControl.endRefreshing()
                                    self.postsCollectionView.isUserInteractionEnabled = true

                                } else if self.totalItems == self.postArray.count {
                                    self.hasFetched = true
                                    self.postsCollectionView.reloadData()
                                    self.refreshControl.endRefreshing()
                                    self.postsCollectionView.isUserInteractionEnabled = true

                                }
                            })
                    } else {
                        
//                        let lastTimeStamp = (postArray.last!.interimMedia.first!.timelineTimeStamp!)
                        let lastRanking = (postArray.last!.interimMedia.first!.ranking)
                        let postRef = ref.child("Hashtags").child(currentHashtag).child("posts")
                        postRef.queryOrdered(byChild: queryOrderdBy)
                            .queryEnding(atValue: lastRanking)
                            .queryLimited(toLast: UInt(limit))//10
                            .observeSingleEvent(of: .value,with: { (snapshot) in
                                
                                print(snapshot.children.allObjects.count-1," fdsjhafljkdsahfljksadhjklfdhsajfkhadsfhjkadsfjhladsjl;")
                                self.totalItems += snapshot.children.allObjects.count-1
                                
                                //var i = 0
                                for case let child as DataSnapshot in snapshot.children.reversed() {
                                    var runAll = true
                                    let keyvalue = child.key
                                    let postIDDoubleVal = keyvalue.split(separator: ":")[1]
                                    
                                    let timelineTimestamp = child.childSnapshot(forPath: "timeStamp").value as! Double
                                    if (nil == child.childSnapshot(forPath: "ranking").value as? Double) {
                                        //the problem has to do with the fact that the pst with aa problm is the last one.
                                        print("fdsdsfdsflkjshfjkshkfsd",self.totalItems)
                                        self.totalItems-=1
                                        
                                        if self.totalItems == self.postArray.count {
                                            
                                            self.postsCollectionView.reloadData()
                                            self.refreshControl.endRefreshing()
                                            self.postsCollectionView.isUserInteractionEnabled = true
                                            if let p3 = self.p3Refrence {
                                                if wasCalledOnP3 {
                                                    p3.updatePageVCInExplore(postARR: self.postArray)
                                                }
                                            }
                                        }
                                        runAll = false
                                    }
                                    if runAll {
                                        let timelineRanking = child.childSnapshot(forPath: "ranking").value as! Double
                                        
                                        if lastRanking != timelineRanking {
                                            
                                            let uid = keyvalue.split(separator: ":")[0]

                                            self.fetchUsersPost(uid: "\(uid)",timelineTimeStamp: timelineTimestamp) { post in
                                                
                                                if post != nil {
                                                    post?.interimMedia.first?.ranking = timelineRanking
                                                    self.postArray.append(post!)
                                                    print(self.totalItems,"==",self.postArray.count," fjsdhafjksdlahfjklhsdafjkdhddasljkf")
                                                    if self.totalItems == self.postArray.count {
                                                        self.postsCollectionView.reloadData()
                                                        self.refreshControl.endRefreshing()
                                                        self.postsCollectionView.isUserInteractionEnabled = true
                                                        
                                                        if let p3 = self.p3Refrence {
                                                            if wasCalledOnP3 {
                                                                p3.updatePageVCInExplore(postARR: self.postArray)
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    //the problem has to do with the fact that the pst with aa problm is the last one.
                                                    print("fdshjakdhjskfjdhksdafjkhdsad",self.totalItems)
                                                    self.totalItems-=1
                                                    
                                                    if self.totalItems == self.postArray.count {
                                                        
                                                        self.postsCollectionView.reloadData()
                                                        self.refreshControl.endRefreshing()
                                                        self.postsCollectionView.isUserInteractionEnabled = true
                                                        if let p3 = self.p3Refrence {
                                                            if wasCalledOnP3 {
                                                                p3.updatePageVCInExplore(postARR: self.postArray)
                                                            }
                                                        }
                                                    }
                                                    print("fdshjakdhjskfjdhksdafjkhdsad",self.totalItems)
                                                }
                                            }
                                        } else {
                                        }
                                    }
                                }
                            })
                    }
        //        }
            }

额外:在研究此问题时,我遇到了这个Query rows using Order by A,if A values are the same,Order by B as the second standard,其含义在我的提取中没有看到。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)