Flutter Firestore使设备上的runTransaction瞬时生效 [英] Flutter Firestore make runTransaction instantaneous on device

查看:58
本文介绍了Flutter Firestore使设备上的runTransaction瞬时生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从开始使用 DatabaseReference.runTransaction 函数,我对此有疑问.

Since starting to use the DatabaseReference.runTransaction function, I have a problem with it.

观看了最新的 Google Developers Flutter促销视频,现在,我有信心准确呈现这个问题!

Having watched the latest Google Developers Flutter promotion video, I now have the confidence to present this problem accurately!

使用 在此处看到.当他点按项目时,即updateData被更新,计数器也立即被更新,这非常好,并且预期的行为. 这表示,您执行更新的设备会立即更新,但另一台设备从服务器提取的延迟.

Using DatabaseReference.updateData will pass the information instantaneously to the Stream<QuerySnapshot>. This can be seen here. The moment he taps the item, i.e. updateData is updated, the counter is also immediately updated, which is very nice and expected behavior. This means that the device you execute the update on updates instantly, but the other device has a delay fetching from the server.

过渡到runTransaction的那一刻,此功能完全丢失,您将不得不等待设备未处理但由Firestore发送的常规更新. 查看新的实现,您可以清楚地看到存在延迟并且比两个设备相同的时间更新的情况更糟.从这一点可以清楚地得出结论,设备上没有数据进行数据更新,这对于UI来说是非常烦人的.

The moment you transition to runTransaction, this functionality is completely lost and you will have to wait for the regular update that is not handled on device, but sent from Firestore. Looking at the new implementation, you can clearly see that there is a delay and worse than this that both devices update at the same time. From this one can clearly derive that there is no on device data update, which is very annoying for UI.

不搜索,因为我显然是自己实现的,这意味着我自己管理更新,在这种情况下,我会在点击时立即在内部更新计数器在更新程序上.

I am not searching for a workaround because I have obviously implemented that myself, which means that I am managing my update on my own, in this case I would update the counter internally the moment I tap on the updater.

我想找出的是是否有一种方法可以启用 瞬时 行为并使用 runTransaction .

What I want to find out is whether or not there is a way to enable the instantaneous behavior with runTransaction.

推荐答案

我怀疑是否有可能,否则就不会成为交易. 交易必须是 ACID ,因此需要在服务器(服务器)的中央进行协调.

I doubt that is possible, otherwise it wouldn't be a transaction. A transaction has to be ACID and therefore needs to be coordinated at a central point - the server.

这就是为什么在事务处理中没有本地更新随后会同步到服务器的原因.

This is why with a transaction there is no local update that is then synchronized to the server.

这篇关于Flutter Firestore使设备上的runTransaction瞬时生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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