脱机时如何丢弃待处理的DocumentReference写入?

编程入门 行业动态 更新时间:2024-10-25 02:19:09
本文介绍了脱机时如何丢弃待处理的DocumentReference写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Firebase Firestore文档在地图上发布用户的位置,以便他们彼此看到.当它们所有人都具有良好的连接性时,这种方法很好用,但是有时它们的移动设备无法连接到Firebase服务器,并且写入似乎已被缓存:每当它们恢复连接性时,所有待处理的位置写入都将批量发送.

I'm using Firebase Firestore documents to publish the location of my users on a map, so they see each other. This works fine when all of them have good connectivity, but sometimes their mobiles can't connect to the Firebase servers and it seems that the writes are cached: whenever they recover connectivity all the pending location writes are sent in bulk.

对其他用户的影响是,他们看到一个人的位置停下来,过了一会儿,他们才开始真正快速地移动,直到地图位置捕获到真实的价值为止.这很烦人,而且浪费带宽.

The effect for other users is that they see the position of a person stop, and after a while they start moving really quick until the map position catches the real value. This is annoying and a waste of bandwidth.

我曾尝试禁用持久性缓存,但这无济于事(只有在Transmisor应用程序死掉时,它才有帮助,但前提是只要生存,位置就会缓存在内存中).

I have tried disabling the persistence cache but this doesn't help (it would only help if the transmisor app would die, but as long as it lives the positions are cached in memory).

也许问题是我不应该为此目的使用文档,并且还有另一个Firebase机制可以出于实时通信的目的而丢弃陈旧的写入数据?

Maybe the problem is that I shouldn't be using documents for this purpose and there is another Firebase mechanism which allows discarding stale write data for the purposes of real time communication?

推荐答案

将设备脱机时执行的所有写入操作排队,直到重新建立与Firebase服务器的连接为止.不幸的是,没有API可以帮助您控制哪些写入操作已排队,哪些未排队.

All write operations that are performed while the device is offline are queued until the connection with the Firebase servers is reestablished. Unfortunately, there is no API that can help you control which write operation are queued and which are not.

我能想到的最简单的解决方案是使用 Firestore交易,它们当前未持久保存到磁盘上,因此当应用程序脱机时将丢失.

The simplest solution I can think of is to use Firestore transactions, which are currently not persisted to disk and thus will be lost when the application is offline.

因此,不支持事务脱机使用,不能将其缓存或保存以备后用.这是因为事务绝对需要与服务器进行往返通信,以确保事务内的代码成功完成.因此,您只能在在线时使用交易,因为交易取决于网络.

So, transactions are not supported for offline use, they can't be cached or saved for later. This is because a transaction absolutely requires round trip communications with server in order to ensure that the code inside the transaction completes successfully. So you can use transaction only while online because the transactions are network dependent.

更多推荐

脱机时如何丢弃待处理的DocumentReference写入?

本文发布于:2023-11-09 20:24:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DocumentReference

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!