本文介绍了Firestore具有大型集合的慢查询,除非禁用了离线持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firestore回收器适配器绑定到firestore中的大型集合的查询.

I am using a Firestore Recycler Adapter to bind to a query of a large collection in firestore.

据我了解GitHub中的文档,Firestore Recycler Adapter使用.addSnapshotListener()而不是.get()方法.

As I understand the documents in GitHub, the Firestore Recycler Adapter uses .addSnapshotListener(), not the .get() method.

该馆藏有5,000个文档,但仅限于100个.

The collection has 5,000 documents, of which I will limit to just 100.

Query query = fsDB.collection("Users").document(user_id).collection("posts")
.orderBy("date_created).orderBy("topic").limit(100);

现在,当我连接到Internet并启用了离线持久性时,此查询平均需要90秒钟才能调用onDataChanged().我认为这是因为回收站正在从设备上的内存或缓存中获取数据,然后对它们进行排序(!),然后再从网络中获取数据.

Now, when I am connected to the internet, and when offline persistence is enabled, this query takes an average of 90 seconds before onDataChanged() is called. I think that is because the recycler is getting data from the memory or cache on the device, then sorting it (!) before getting the data from the network.

因为,当禁用离线持久性时,查询仅需要2-3秒.

BECAUSE, when offline persistence is disabled, the query only takes 2-3 seconds.

启用离线持久性后,如何使用此查询更快?还是有一种方法可以使侦听器在搜索内存/缓存之前访问网络索引?

How can I use this query to be faster while offline persistence is enabled? Or is there a way to make it so that the listener accesses the network indexes before searching the memory/cache?

类似...

FirestoreRecyclerOptions<Reed> options = new FirestoreRecyclerOptions.Builder<>()
.setQuery(query, Reed.class)
.setFirst(FirebaseFirestore.getInstance fsDB);

firestore索引在客户端不可用吗?

Are the firestore indexes not available on client side?

使用Android设备Firestore 15.0.0

Using firestore 15.0.0, Android device

推荐答案

离线查询没有像应用程序在线时那样得到优化.快速查询是Firestore后端的功能,离线时显然不可用.

Offline queries are not optimized like they are when the app is online. Fast queries are a feature of the Firestore backend which is obviously unavailable when offline.

另请参阅: Firestore作为离线持久性的可靠性如何机制?

这篇关于Firestore具有大型集合的慢查询,除非禁用了离线持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:32