使用Firebase构建社交网络

时间:2016-12-07 20:10:24

标签: android firebase firebase-realtime-database nosql

我目前正在开发用于共享图片的基本社交网络Android应用。已经有PHP / mySQL后端,但由于我喜欢的一些功能(例如安全性,快速读/写)而考虑迁移到Firebase。

所以,我有userspostsfollowerslikescomments(就像现在所有其他社交网络一样)。

长话短说,我想知道我是否正确。 根据{{​​3}}及其示例,我应该将一些JSON树中的唯一键包含到这样的其他键中(示例来自文档):

// An index to track Ada's memberships
{
  "users": {
    "alovelace": {
      "name": "Ada Lovelace",
      // Index Ada's groups in her profile
      "groups": {
         // the value here doesn't matter, just that the key exists
         "techpioneers": true,
         "womentechmakers": true
      }
    },
    ...
  },
  "groups": {
    "techpioneers": {
      "name": "Historical Tech Pioneers",
      "members": {
        "alovelace": true,
        "ghopper": true,
        "eclarke": true
      }
    },
    ...
  }
}

这是否意味着我必须将帖子,评论,关注者等的密钥包含在我的用户树中,如下所示:

{
  "users": {
    "alovelace": {
      "name": "Ada Lovelace",
      "profileImage": "http://blabla.bla?xyzooqlL.png",
      "about:" : "Exit light, enter night",
      "country": "Neverland"
      // Index Ada's posts in her profile
      "posts": {
         // the value here doesn't matter, just that the key exists
         "post123": true,
         "post234": true
      },
      // all comments this user wrote
      "comments": {
         "comment123": true
      },
      // all posts this user liked
      "likes": {
         "post123": true
      },
      "followers": {
         "user123": true,
         "user234": true
      }
    },
    ...
  },
  "posts": {
    "post123": {
      "image": "www.bla.bla/sadsadsa.png",
      "description": "Hue hue hue",
      "likes": {
        "alovelace": true,
        "ghopper": true,
        "eclarke": true
      },
      "comments": {
        "comment123": true,
      }
    },
    "post234": {
     "image": "www.bla.bla/233arweeq.png",
      "description": "This is nice",
      "likes": {
        "eclarke": true
      },
      "comments": {
        "comment234": true,
      }
    },
  "comments": {
    "comment123": {
      "userId": "alovelace"
      "text": "cool",
      "date": "current"
    }
   },
    ...
  }
}

如果我有5000个粉丝,2000个粉丝,1500个帖子喜欢,这不是有点太多了吗? 在获取用户或任何其他对象时,我还将获取该对象中的所有键。想象一下,使用所有这些数据获取15个非常活跃的用户。

如果您有任何建议我应该如何构建数据,请告诉我。 任何类型的反馈都会有用。

感谢。

0 个答案:

没有答案