<bdo id='8frTY'></bdo><ul id='8frTY'></ul>

    <i id='8frTY'><tr id='8frTY'><dt id='8frTY'><q id='8frTY'><span id='8frTY'><b id='8frTY'><form id='8frTY'><ins id='8frTY'></ins><ul id='8frTY'></ul><sub id='8frTY'></sub></form><legend id='8frTY'></legend><bdo id='8frTY'><pre id='8frTY'><center id='8frTY'></center></pre></bdo></b><th id='8frTY'></th></span></q></dt></tr></i><div id='8frTY'><tfoot id='8frTY'></tfoot><dl id='8frTY'><fieldset id='8frTY'></fieldset></dl></div>
      1. <legend id='8frTY'><style id='8frTY'><dir id='8frTY'><q id='8frTY'></q></dir></style></legend>
        <tfoot id='8frTY'></tfoot>

      2. <small id='8frTY'></small><noframes id='8frTY'>

      3. 始终保持 Firebase 实时数据库中的数据同步

        时间:2023-07-30
          <bdo id='RAr9C'></bdo><ul id='RAr9C'></ul>
          • <small id='RAr9C'></small><noframes id='RAr9C'>

              <tfoot id='RAr9C'></tfoot>
                <tbody id='RAr9C'></tbody>

                <legend id='RAr9C'><style id='RAr9C'><dir id='RAr9C'><q id='RAr9C'></q></dir></style></legend>

                1. <i id='RAr9C'><tr id='RAr9C'><dt id='RAr9C'><q id='RAr9C'><span id='RAr9C'><b id='RAr9C'><form id='RAr9C'><ins id='RAr9C'></ins><ul id='RAr9C'></ul><sub id='RAr9C'></sub></form><legend id='RAr9C'></legend><bdo id='RAr9C'><pre id='RAr9C'><center id='RAr9C'></center></pre></bdo></b><th id='RAr9C'></th></span></q></dt></tr></i><div id='RAr9C'><tfoot id='RAr9C'></tfoot><dl id='RAr9C'><fieldset id='RAr9C'></fieldset></dl></div>
                  本文介绍了始终保持 Firebase 实时数据库中的数据同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在重新开发我的一个应用程序,该应用程序通过从网站而不是官方 API 获取原始数据来更新其内部 SQLite 数据库.

                  I'm currently re-working an app of mine which updates it's internal SQLite database by fetching raw data from an website, not an official API.

                  由于这很容易出错,我想将数据处理从客户端移到后端服务器.这个想法是让一个脚本每天在服务器上运行多次——类似于之前的客户端行为——并将数据存储在 Firebase 实时数据库中.然后,所有客户端不再需要自己处理数据,而是从 Firebase DB 请求解析后的数据.

                  As this is quite error-prone I'd like to move the data processing out of the client into an backend server. The idea is to have a script running on the server multiple times a day - similar to the client behaviour before - and storing the data in a Firebase Realtime Database. Then, all clients no longer have to process the data themselves but rather request parsed data from the Firebase DB.

                  我只是想知道保持数据同步的最佳方法是什么.我提出了两个想法,但由于我对 Firebase 不太熟悉,我不知道哪个更可取.

                  I'm just wondering what's the best approach to keep the data synced. I came up with two ideas, but as I'm not too familiar with Firebase I don't know what's preferable.

                  我可以想象通过在某些节点上使用 keepSynced()setPersistenceEnabled() 来保持客户端上的数据同步.但我不确定当应用程序处于后台时这是否会使数据保持最新.我也担心这种方法的电池和网络使用情况.第三点是同时连接的数量,我想用这种方法每个客户端都会一直连接,对吧?

                  For one I could imagine keeping the data on the client in sync by using keepSynced() and setPersistenceEnabled() on some nodes. But I'm unsure whether this will keep data up to date when the app is in background. As well I'm worried about the battery and network usage of this approach. A third point is the amount of simultaneous connections, I quess with this approach every client will be connected all the time, right?

                  第二种方法是使用 FCM 通知客户端,只要他感兴趣的节点之一发生变化,例如使用 Firebase Cloud Functions 监听事件并触发消息.然后客户端将goOnline() 与数据库同步并再次goOffline().这将避免大量的连接,并减少电池和网络的使用.但我不确定如何在离线时将所有数据保留在设备上?我不想使用 SQLite 数据库将数据保存在设备上.setPersistenceEnabled() 是否足以在设备上保留特定数量的数据库注释?

                  The second approach would be to use FCM to notify the client whenever there is a change in one of his interested nodes, e.g. using Firebase Cloud Functions to listen for event and trigger the message. Then the client would goOnline() to sync with the database and goOffline() again. This would avoid the huge amount of connections as well as reduce battery and network usage. But I'm unsure on how to keep all the data on the device while offline? I don't want to use a SQLite database to keep data on the device. Is setPersistenceEnabled() sufficient to keep a particular amount of database notes on the device?

                  还是两者兼而有之?在需要的节点和 goOnline()/goOffline() 上设置 keepSynced()setPersistenceEnabled() 取决于云消息?

                  Or is a mix of both the way to go? Setting keepSynced() and setPersistenceEnabled() on the needed nodes and goOnline()/goOffline() depending on cloud messages?

                  欢迎任何基于自己经验的帮助或建议!

                  Any help or advices based on own expiriences welcome!

                  推荐答案

                  您的第一种方法是尝试确保 Android 应用始终与 Firebase 数据库后端保持开放连接.这已被询问/尝试过(请参阅此处,这里),绝对有可能.但是您将与 Android 更新作斗争,这些更新专门试图通过应用中的这种行为来减少电池使用量.

                  Your first approach is trying to ensure the Android app always has an open connection to the Firebase Database backend. This has been asked/tried before(see here, here), and is definitely possible. But you'll be fighting with Android updates, which are specifically trying to reduce battery usage by this type of behavior in apps.

                  第二种方法确实更好.我经常将其称为推送同步",因为您正在发送推送通知(通过 FCM)来触发数据同步.(另外:这是许多应用程序都遵循的拉同步"模式的文字游戏).使用这种方法的应用示例是 2016 年 Google 的 Android I/O 应用,代码在 Github.代码有点复杂,但是 实际同步在这里和(iirc)它是 由此触发.

                  The second approach is indeed better. I often refer to it as "push to sync", since you're sending a push notification (through FCM) to trigger a data sync. (plus: it's a word play on the "pull to sync" pattern so many apps follow). An example of an app using this approach is Google's I/O app for Android from 2016, the code for which is on Github. The code is a bit convoluted, but the actual sync is here and (iirc) it is triggered through this.

                  这篇关于始终保持 Firebase 实时数据库中的数据同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:刷新令牌后如何恢复主题订阅? 下一篇:onTokenRefresh 不会在签名的 APK 中被调用,如果之前安装的应用版本没有实现 FCM

                  相关文章

                    <legend id='Y0lI2'><style id='Y0lI2'><dir id='Y0lI2'><q id='Y0lI2'></q></dir></style></legend>
                  1. <tfoot id='Y0lI2'></tfoot>
                  2. <i id='Y0lI2'><tr id='Y0lI2'><dt id='Y0lI2'><q id='Y0lI2'><span id='Y0lI2'><b id='Y0lI2'><form id='Y0lI2'><ins id='Y0lI2'></ins><ul id='Y0lI2'></ul><sub id='Y0lI2'></sub></form><legend id='Y0lI2'></legend><bdo id='Y0lI2'><pre id='Y0lI2'><center id='Y0lI2'></center></pre></bdo></b><th id='Y0lI2'></th></span></q></dt></tr></i><div id='Y0lI2'><tfoot id='Y0lI2'></tfoot><dl id='Y0lI2'><fieldset id='Y0lI2'></fieldset></dl></div>
                        <bdo id='Y0lI2'></bdo><ul id='Y0lI2'></ul>

                      <small id='Y0lI2'></small><noframes id='Y0lI2'>