Firestore的hasPendingWrites()对已删除的文档返回false [英] Firestore's hasPendingWrites() returns false on deleted document

查看:69
本文介绍了Firestore的hasPendingWrites()对已删除的文档返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注册了一个侦听器,该侦听器侦听查询的更改.删除/删除文档后,它需要检查更改是否是本地的.如果更改是本地更改,则会显示一条消息.如果不是本地对象,则仅删除该对象.

I have a registered a listener which listens to changes to a query. When a document is removed/deleted, it needs to check if the change was local or not. If the change is local, a message is displayed. If it was not local, the object is just removed.

问题在于,在侦听器中检查时,hasPendingWrites()返回false.这是为什么?根据Firestore的文档,应该是true第一次,因为在更改本地缓存后立即触发了侦听器.

The problem is that hasPendingWrites() returns false when checked in the listener. Why is that? According to Firestore docs, it should be true the first time as the listener is immediately triggered on alteration of the local cache.

AsyncArrayHandler的简化代码,在激活侦听器时调用:

Simplified code of AsyncArrayHandler, which is called when the listener is activated:

for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges())
{
    changeIsMadeLocal = documentChange.getDocument().getMetadata().hasPendingWrites();
    switch (documentChange.getType())
    {
        case REMOVED:
            if (changeIsMadeLocal)
            {
                //do stuff here
            }
        break;
    }
}

推荐答案

对于每个人(看着视图,几乎没有人)遇到与我相同的问题,Firebase正在对其进行调查,这似乎是一个错误仅存在于某些设备和仿真器上.他们不太确定它是从哪里来的,而是试图找出来.

For everyone(and looking at the views, that's almost no one)running into the same problem as me, Firebase is looking into it and it seems it's a bug only present on certain devices and emulators. They are not quite sure where it's coming from but trying to find out.

当他们给我更多信息时,我将编辑此答案.

When they give me more information, I'll edit this answer.

这篇关于Firestore的hasPendingWrites()对已删除的文档返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆