新闻提要的 Firebase 扇出结构 [英] Firebase fan-out structure for news feed
问题描述
我有一个包含 posts
、users
和其他节点(如经典社交媒体应用)的数据库.
I have a database with posts
, users
and other nodes like classic social-media app.
我将继续在我的应用程序中实施最佳实践.现在我想重写我的新闻条(我关注的用户帖子(如 Instagram 中的主页标签)).
I'm continuing implementing best-practices to my application. And now I want to rewrite my news strip (posts of users, that I follow (like home tab in Instagram)).
我已经阅读了一些关于 fan-out
策略的信息,现在我对如何正确执行它感到困惑.
I have read some info about fan-out
strategy and now I'm confused in how to do it properly.
所以,我有两个机会:
喜欢这里:每次用户添加新的
post
,这个post
的完整信息将被复制到users-timeline(users news strip)/UID/postId:此
.并且每次编辑都会编辑此用户
的所有关注者
的完整信息post
的每次提及.
Like here: Every time user adds new
post
, thispost
with full information will be copied tousers-timeline(users news strip)/UID/postId: FULL INFO
to allfollowers
of thisuser
. And every edit will edit each mention of thispost
.
每次用户添加新的post
,这个postID
会被复制到user-timeline(users news strip)/UID/postId: true
给这个 user
的所有 followers
.而且每次编辑都只会编辑源帖子.
Every time user adds new post
, this postID
will be copied to user-timeline(users news strip)/UID/postId: true
to all followers
of this user
. And every edit will edit only source post.
Firebase 哪种逻辑更好?
Which logic is better with Firebase?
推荐答案
我建议你使用 David's East 解决方案.正如我在他的帖子中看到的,他使用 Firebase 非规范化和数据扁平化,这是 Firebase 中的最佳常见做法.
I suggest you using David's East solution. As I see in his post, he uses Firebase denormalization and data flatten, which are the best common practices within Firebase.
我还建议您阅读 NoSQL 数据建模技术 和 为复杂应用正确构建 Firebase 数据 为了更好地理解.
I also recommend you reading NoSQL Data Modeling Techniques and Structuring your Firebase Data correctly for a Complex App for a better understanding.
如果你有 SQL 背景,我建议你也看看 David 的 East 教程,适用于 SQL 开发人员的 Firebase 数据库.
If you have a SQL background, I recommend you seeing also David's East tutorial, The Firebase Database For SQL Developers.
这篇关于新闻提要的 Firebase 扇出结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!