Cloud Firestore批处理写入如何在离线模式下工作 [英] How does the Cloud Firestore Batched writes work in offline mode

查看:55
本文介绍了Cloud Firestore批处理写入如何在离线模式下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有关Cloud Firestore的文档中,批量写入我读到您甚至可以在用户设备离线时执行批量写入."

In the doc about Cloud Firestore Batched writes I read "You can perform batched writes even when the user's device is offline."

这是可以关闭还是默认关闭,因为文本显示为可以".如果Cloud Firestore交易处于离线状态,则该交易将失败,我希望批量写入操作也能做到

Can this be turned off or is it off by default since the text say "can". The Cloud Firestore Transaction will fail if it´s offline and I would like Batched writes to do the same

我觉得我必须在 OnCompleteListener 中检查结果:

I get the feeling I have to check for the result in the OnCompleteListener:

batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        // offline/online?? 
    }
});

我认为文档应该对此有一些解释

I think the Doc should contain some explanation on this

推荐答案

存在Firestore事务,以便可以从客户端执行原子性的读取,修改,写入操作.为了保证这一点,客户需要在线.

Firestore transactions exist to make it possible to perform atomic read-modify-write operations from the client. In order to make this guarantee the clients need to be online.

批量写入是一种有限的事务,专门用于使用户即使在脱机时也能够以全有或全无的方式更改多个文档.

Batched writes are a limited kind of transaction that exists specifically to allow users to be able to change multiple documents in an all-or-nothing manner even while offline.

如果您不需要或不想在离线状态下写东西,只需使用常规交易即可:它将处理您是否在线,如果离线则失败.您没有义务阅读交易中的任何内容.

If you don't need or want to be able to write while offline just use a regular transaction: it will handle checking whether or not you're online and will fail if you're offline. You're not obligated to read anything in the transaction.

为此目的,无法在 OnCompleteListener 中检查结果是否进行批量写入.您无法阻止该回调中的任何内容,因为只有在成功将写入成功应用于服务器后,该回调才会被调用.

Checking the result in the OnCompleteListener for a batch write does not work for this purpose. You couldn't prevent anything in that callback because it is only called once the write has been successfully applied to the server.

这篇关于Cloud Firestore批处理写入如何在离线模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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