【发布时间】:2020-02-24 01:34:43
【问题描述】:
我有一个CollectionView,它显示按位置排序的项目,我正在尝试按给定数量(例如 20 个项目)对它们进行分页。
我使用Geofire 按位置对它们进行排序,但问题是它不支持受结果计数限制的查询,因此如果不访问所有 ID,我就无法获得整个页面。
我想出了在第一页上按位置排序的给定位置内的所有项目键的想法:
locationQuery?.observe(.keyEntered, with: { (key, location) in
print("KEY: ", key, " and location: ", location.coordinate)
itemKeys.append(key)
})
locationQuery?.observeReady {
print("All item keys loaded. There are: ", itemKeys.count, " items in radius")
locationQuery?.removeAllObservers()
completion(itemKeys) //itemKeys.count would be the number of cells in the collectionView
}
然后保存它们,并在每个页面中使用 Firebase rererence.child(itemKeyInArray) 检索和查询 itemKeys 的下一个 (pageAmount)。
我对此的主要担忧是,如果我在数据库中有非常多的项目集,那么它对所有键的迭代(和排序)效率会有多高。
另一种方法是从小半径开始,并在每个页面中增加它直到限制,尽管它看起来更有效,但我仍然需要半径内的项目总数(计算@中的单元格数987654325@)
按位置对结果进行分页的正确方法是什么?
【问题讨论】:
标签: ios swift firebase pagination geofire