热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

通过慢速互联网连接保存到3个firebase位置-Saveto3firebaselocationswithaslowinternetconnection

SometimesImhavingissueswithfirebasewhentheuserisonaslowmobileconnection.Whentheuse

Sometimes I'm having issues with firebase when the user is on a slow mobile connection. When the user saves an entry to firebase I actually have to write to 3 different locations. Sometimes, the first one works, but if the connection is slow the 2nd and 3rd may fail.

有时,当用户使用慢速移动连接时,我遇到了firebase问题。当用户将条目保存到firebase时,我实际上必须写入3个不同的位置。有时,第一个工作,但如果连接速度慢,第二个和第三个可能会失败。

This leaves me with entries in the first location that I constantly need to clean up.

这使我在第一个位置输入了我经常需要清理的条目。

Is there a way to help prevent this from happening?

有没有办法帮助防止这种情况发生?

            var newTikiID = ref.child("tikis").push(tiki, function(error){

                if(!error){

                    console.log("new tiki created")

                    var tikiID = newTikiID.key()

                    saveToUser(tikiID)
                    saveToGeoFire(tikiID, tiki.tikiAddress)

                } else {

                    console.log("an error occurred during tiki save")

                }

            });

2 个解决方案

#1


1  

There is no Firebase method to write to multiple paths at once. Some future tools planned by the team (e.g. Triggers) may resolve this in the future.

没有Firebase方法一次写入多个路径。团队计划的一些未来工具(例如触发器)可能在将来解决此问题。

This topic has been explored before and the firebase-multi-write README contains a lot of discussion on the topic. The repo also has a partial solution to client-only atomic writes. However, there is no perfect solution without a server process.

之前已经探讨了这个主题,firebase-multi-write README包含了很多关于该主题的讨论。 repo还有一个仅限客户端原子写入的部分解决方案。但是,没有服务器进程就没有完美的解决方案。

It's important to evaluate your use case and see if this really matters. If the second and third writes failed to write to a geo query, chances are, there's really no consequence. Most likely, it's essentially the same as if the first write had failed, or if all writes had failed; it won't appear in searches by geo location. Thus, the complexity of resolving this issue is probably a time sink.

评估您的用例非常重要,看看这是否真的很重要。如果第二次和第三次写入无法写入地理查询,则可能没有任何后果。最有可能的是,它与第一次写入失败或者所有写入都失败的情况基本相同;它不会出现在地理位置的搜索中。因此,解决这个问题的复杂性可能是一个时间问题。

Of course, it does cost a few bytes of storage. If we're working with millions of records, that may matter. A simple solution for this scenario would be to run and audit report that detects broken links between the data and geofire tables and cleans up old data.

当然,它确实需要几个字节的存储空间。如果我们正在处理数百万条记录,那可能很重要。这种情况的一个简单解决方案是运行和审计报告,检测数据和地理表格之间断开的链接并清理旧数据。

If an atomic operation is really necessary, such as gaming mechanics where fairness or cheating could be an issue, or where integrity is lost by having partial results, there are a couple options:

如果确实需要原子操作,例如公平或作弊可能成为问题的游戏机制,或者通过获得部分结果而导致完整性丢失,则有以下几种选择:

1) Master Record approach

1)Master Record方法

Pick a master path (the one that must exist) and use security rules to ensure other records cannot be written, unless the master path exists.

选择主路径(必须存在的路径)并使用安全规则以确保无法写入其他记录,除非存在主路径。

".write": "root.child('maste_path').child(newData.child('master_record_id')).exists()"

2) Server-side script approach

2)服务器端脚本方法

Instead of writing the paths separately, use a queue strategy.

不使用单独编写路径,而是使用队列策略。

  1. Create an single event by writing a single event to a queue
  2. 通过将单个事件写入队列来创建单个事件

  3. Have a server-side process monitor the queue and process events
  4. 让服务器端进程监视队列并处理事件

  5. The server-side process does the multiple writes and ensures they all succeed
  6. 服务器端进程执行多次写入并确保它们都成功

  7. If any fail, the server-side process handles rollbacks or retries
  8. 如果有任何失败,服务器端进程将处理回滚或重试

By using the server-side queue, you remove the risk of a client going offline between writes. The server can safely survive restarts and retry events or failures when using the queue model.

通过使用服务器端队列,可以消除客户端在写入之间脱机的风险。使用队列模型时,服务器可以安全地重新启动并重试事件或失败。

#2


0  

I have had the same problem and I ended up choosing to use condition Conditional Request with the Firebase REST API in order to write data transactionally. See my question and answer. Firebase: How to update multiple nodes transactionally? Swift 3 .

我遇到了同样的问题,我最终选择使用带有Firebase REST API的条件条件请求来以事务方式写入数据。看看我的问题和答案。 Firebase:如何以事务方式更新多个节点?斯威夫特3。

If you need to write concurrently (but not transactionally) to several paths, you can do that now as Firebase supports multi-path updates. https://firebase.google.com/docs/database/rest/save-data https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html

如果您需要同时(但不是事务性地)写入多个路径,则可以立即执行此操作,因为Firebase支持多路径更新。 https://firebase.google.com/docs/database/rest/save-data https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html


推荐阅读
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • 在编写业务代码时,常常会遇到复杂的业务逻辑导致代码冗长混乱的情况。为了解决这个问题,可以利用中间件模式来简化代码逻辑。中间件模式可以帮助我们更好地设计架构和代码,提高代码质量。本文介绍了中间件模式的基本概念和用法。 ... [详细]
  • 本文介绍了在wepy中运用小顺序页面受权的计划,包含了用户点击作废后的从新受权计划。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • switch语句的一些用法及注意事项
    本文介绍了使用switch语句时的一些用法和注意事项,包括如何实现"fall through"、default语句的作用、在case语句中定义变量时可能出现的问题以及解决方法。同时也提到了C#严格控制switch分支不允许贯穿的规定。通过本文的介绍,读者可以更好地理解和使用switch语句。 ... [详细]
  • Html5-Canvas实现简易的抽奖转盘效果
    本文介绍了如何使用Html5和Canvas标签来实现简易的抽奖转盘效果,同时使用了jQueryRotate.js旋转插件。文章中给出了主要的html和css代码,并展示了实现的基本效果。 ... [详细]
  • 本文介绍了在使用vue和webpack进行异步组件按需加载时可能出现的报错问题,并提供了解决方法。同时还解答了关于局部注册组件和v-if指令的相关问题。 ... [详细]
  • WebSocket与Socket.io的理解
    WebSocketprotocol是HTML5一种新的协议。它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送 ... [详细]
  • Redis底层数据结构之压缩列表的介绍及实现原理
    本文介绍了Redis底层数据结构之压缩列表的概念、实现原理以及使用场景。压缩列表是Redis为了节约内存而开发的一种顺序数据结构,由特殊编码的连续内存块组成。文章详细解释了压缩列表的构成和各个属性的含义,以及如何通过指针来计算表尾节点的地址。压缩列表适用于列表键和哈希键中只包含少量小整数值和短字符串的情况。通过使用压缩列表,可以有效减少内存占用,提升Redis的性能。 ... [详细]
  • 本文讨论了编写可保护的代码的重要性,包括提高代码的可读性、可调试性和直观性。同时介绍了优化代码的方法,如代码格式化、解释函数和提炼函数等。还提到了一些常见的坏代码味道,如不规范的命名、重复代码、过长的函数和参数列表等。最后,介绍了如何处理数据泥团和进行函数重构,以提高代码质量和可维护性。 ... [详细]
author-avatar
.
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有