ios - Firebase 数据的过度扁平化有多少?

标签 ios firebase firebase-realtime-database

如果我希望有可以回复的帖子,哪种结构更好?

1)

posts
  908239409234
      postText: "Whats up peeps?"
      replies:
            09283049830294: true
            a9s0dif09iasd9: true

replies
   09283049830294
      text: "Nm breh"
      imageURL: nil
    a9s0dif09iasd9
      text: "Nm breh"
      imageURL: nil

或 2)

posts
   908239409234
      postText: "Whats up peeps?"
      replies:
         09283049830294
            text: "Nm breh"
            imageURL: nil

        a9s0dif09iasd9
             text: "Nm breh"
              imageURL: nil

我看到很多看起来像 #1 的数据库示例,您在其中存储对存储在其他地方的帖子的引用以支持扁平化,但我认为如果可以的话,不只使用选项 2 没有任何优势?

如果用户正在加入一个帖子,他们将拥有帖子的 uid,并且他们可以使用 autoID 在“回复”下添加。

TL;DR,是使用更扁平的方法还是看起来更有效且需要搜索更少信息的方法更好?有什么理由不选择选项 2?

最佳答案

我会拒绝。 2. 原因是没有。 1 您将必须进行查询以获取基于 ID 的回复数据。 使用 firebase,多写少读总是更好。

关于ios - Firebase 数据的过度扁平化有多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38670819/

相关文章:

ios - 滚动时隐藏导航栏而不隐藏状态栏及其背景

ios - 如何在 Swiftui 中更改数组项

javascript - 如何使用云功能在Firebase中获取实时数据库?

android - 批量 Firebase 云消息传递的限制

ios - 如何将多个数据写入firebase?

ios - 使用 LFLiveKit 在 iOS 应用程序中切换到后置摄像头

ios - Ionic 平台命令因 'Cannot read property ' split' of undefined' 突然失败

firebase - 为什么 Firebase Cloud Functions 上的 Node 版本这么旧?

ios - 喜欢使用 firebase 崩溃的反馈。快速点赞-移除点赞

javascript - 使用 Jasmine 模拟 firebase 调用