你有多深的Firebase观察者?

时间:2016-11-17 01:28:35

标签: ios swift facebook firebase firebase-realtime-database

如果我在Firebase(社交网络)中粉碎我的数据:

post
     postId
          postText: This is a post
          postedBy: bob

comment
     commentId
          commentText: This is a comment
          postedBy: fred

like
     likeId
          postedBy: george

然后,当我想建立一个帖子的桌面视图时,我必须嵌入很多观察者。例如:

ref.child("post").observeSingleEventOfType(.Value, withBlock: {
     ref.child(userId).observeSingleEventOfType(.Value, withBlock: {
     })
})

如果您想要提供用户名和其他内容,则需要获取帖子数据和用户数据。然后,如果你想要做很多喜欢你必须把它嵌入其中,如果你想做一些像Instagram这样的预览评论,你必须嵌入另一个...如果你有更多创意的东西要添加它继续像这样:

    ref.child("post").observeSingleEventOfType(.Value, withBlock: {
         ref.child(userId).observeSingleEventOfType(.Value, withBlock: {
              ref.child("comments").observeSingleEventOfType(.Value, withBlock: {
                   ref.child(commentUserId).observeSingleEventOfType(.Value, withBlock: {
                        ref.child("likes").observeSingleEventOfType(.Value, withBlock: {
// create post object here and append to array
                    })
               })
          })
     })
})

所以无论如何,如果你想吸引那些喜欢的人,并且有更多的东西要添加,那就太疯狂了。我的问题是,在Firebase中这样做是否可以,这是否仍然值得使用扇出数据方法?我觉得它会减慢速度,以至于我们最好只将所有内容放在Firebase中的post对象下面。我确实读过,观察者并不是非常昂贵,但对于筑巢它们并没有太多说明。

0 个答案:

没有答案