Clarification On Firebase Denormalization Blog Post

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 08:52:37

The structure detailed in the blog post does not store duplicate comments. We store comments once under /comments then store the name of those comments under /links and /users. These function as pointers to the actual comment data.

Consider the example structure from the post...

{
  users: {
    user1: {
      name: "Alice",
      comments: {
        comment1: true
      }
    },
  },
  comments: {
    comment1: {
      body: "This is awesome!",
      author: "user1"
    }
  }
}

Note that the actual comment data is only stored once.

If we modify /comments/comment1, we don't need to update anything else because we only store the name of the comment under /links and /users, not the actual comment contents.

If we were to remove /comments/comment1, that would remove the only existence of the comment data. However, we still have these "dangling" references to comment1 under /users/user1/comments.

Imagine we delete /comments/comment1, when we try to load Alice's comments, we can look and see that comment1 doesn't exist anymore. Then our application can react accordingly by either a) deleting the reference or b) ignoring the reference and not trying to display the deleted comment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!