如何让iOS应用的Firebase数据库查询速度更快?

问题描述 投票:0回答:1

我正在使用Firebase数据库来查询我的应用程序的gif帖子。这些帖子在应用程序的集合视图中需要很多时间来加载。我不清楚问题是出在应用程序还是数据库上。

POSTS_REF.queryOrderedByKey().queryLimited(toLast: 9).observeSingleEvent(of: .value, with: {  [weak self] (snapshot) in
                self?.tableView.refreshControl?.endRefreshing()

                guard let first = snapshot.children.allObjects.first as? DataSnapshot else { return }
                guard let allObjects = snapshot.children.allObjects as? [DataSnapshot] else { return }
                allObjects.map({(snapshot) in
                    let postId = snapshot.key
                self?.fetchPost(withPostId: postId)

                })
                self?.currentKey = first.key
            })
func fetchPost(withPostId postId: String) {
        Database.fetchPost(with: postId) { (post) in
            self.posts.append(post)
            self.posts.sort(by: { (post1, post2) -> Bool in
                return post1.creationDate > post2.creationDate
            })
            self.collectionView?.reloadData()
        }
    }
ios swift firebase-realtime-database gif
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.