gpt4 book ai didi

java - 在线/离线用户功能 firestore 或实时有什么更好的解决方案?

转载 作者:行者123 更新时间:2023-12-04 10:38:14 25 4
gpt4 key购买 nike

我有一个用户数据库。需要实现只显示在线用户的列表。不幸的是,实时不能按键过滤。所以只有在 Firestore 中才有可能。但是 Firestore 对每个写入/读取/更新操作收费,因此使用该功能可能会非常昂贵,因为用户一直处于离线/在线状态,并且会有很多写入/读取/更新操作。作为一个解决方案,我实时做了单独的表,只保存在线用户,在这里我不需要为写/读/更新付费。但同时,它也在复制数据库,这也不是一个好习惯。

您能否从“价格”和“清洁”的角度分享您对哪种解决方案更好的想法。为 Firestore 付费并使用一个 db,还是使用两个 db 但不为每个操作付费?

最佳答案

What is better solution for online/offline user feature Firestore or realtime?



这取决于您的要求是什么,但您应该 不是 考虑使用其中之一。两者都使用没有任何问题。

Unfortunately realtime does not filter by key.



如果您查看文档,则有一个名为 sorting and filtering data 的部分,您将在其中找到名为 orderByKey() 的方法:

Order results by child keys.



所以实际上可以过滤查询的结果并同时对它们进行排序。

As a solution I did the separate tables in realtime which saves only online users and here I don't need to pay for write/read/update.



这是一个很好的解决方案,您可以继续使用。实际上,Cloud Firestore 和 Firebase 实时数据库可以很好地协同工作。

But at the same time, it is duplicating the database which is also not good practice.



哦,是的。这种做法称为非规范化,是 Firebase 的常见做法。为了更好地理解,我建议您观看此视频, Denormalization is normal with the Firebase Database并从以下帖子中查看我的答案:
  • What is denormalization in Firebase Cloud Firestore?

  • 因此,您可以对数据进行非规范化以获取实际上不可能的查询,或者在涉及 Cloud Firestore 时保存一些写入操作。

    Could you please share your thought on which solution is better from "price" and "clean" point of view. To pay for Firestore and use one db, or use two db but not to pay for each operation?



    使用它们。

    关于java - 在线/离线用户功能 firestore 或实时有什么更好的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60061902/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com