ios - 如何使 iOS 应用程序上的 Firebase 数据库查询更快?
问题描述
我正在使用 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()
}
}
解决方案
推荐阅读
- macos - UserNotifications 使用 UNUserNotificationCenter 并在系统偏好设置中设置警报
- swift - SpriteKit - 弹跳节点恒速/速度?
- c# - 如何为从 Unity 中的 Monobehaviour 继承的类编写单元测试?
- python - 如何将可变对象分配给作为 __init__() 函数的参数传递的类成员?
- angular - 更改路由时,我的数据源中的数据不断添加到现有表数据源中;Angular 7材料设计问题
- php - 批量更改订单信息作为特定 Woocommerce 订单 ID 的订单状态
- google-sheets - 如何在 Google 表格中创建简单的复制和保存功能?
- react-admin - 为多个 api 请求重写 Dataprovider 破坏了它,现在返回错误“无法读取未定义的属性 'hasOwnProperty'”
- python - 为什么我在 Keras 中得到负的 false_negative 计数(例如 -10)?
- c# - 将多个 rdlc 合并到单个 reportviewer 控件中