- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个关于 Firebase 数据库中数据结构最佳实践的快速问题。
我希望我的应用程序的用户能够维护好友列表。 firebase 文档建议创建一个尽可能扁平的模式(不确定在这种情况下这是否是正确的词)。因此,我认为将数据库中的 friend 部分与玩家部分分开是个好主意,如下所示:
{
"players":{
"player1id":{
"username":"john",...
},
"player2id": ...,
"player3id": ...
}
"friends": {
"player1id"{
"friends":{
"friend1Id":true,
"friend2Id":true
}
},
}
"player2id"{
"friends":{
"friend1Id":true,
"friend2Id":true
}
},
}
}
所以我的问题如下:
这对我的架构来说是一个好的设计吗?
拉取一个玩家的好友列表时,会拉取所有玩家的好友列表吗?如果是这样,可以避免这种情况吗?
此外,一旦应用程序拥有 friend 的所有 ID,最好的方法是什么才能提取有关 friend 的其他信息。例如获取他们所有的用户名,这些用户名将作为字符串存储在他们的玩家资料中。
最佳答案
Is this a good design for my schema?
您的思考方向已经正确。然而,“ friend ”节点可以简化为:
"friends": {
"player1id": {
"friend1Id":true,
"friend2Id":true
}
}
请记住,Firebase 节点名称不能使用字符点 (.)。因此,如果您的 ID 是整数,例如 1、2 和 3,一切都可以,但如果 ID 是用户名,请小心(例如“super123”可以,但“super.duper”则不行)
When pulling a friends list for one player, will the friends lists of EVERY player be pulled? and if so, can this be avoided?
没有。如果你拉/friends/1 它显然不会拉/friends/2 等。
Also, what would be the best way to then pull in additional information about the friends once the app has all of their IDs. e.g. getting all of their user names which will be stored as a string in their player profile.
遍历 ID 并再次从 Firebase 获取相应的节点。例如,如果用户 1 有 friend 2、3 和 4,则使用 for 循环获取/players/2、/players/3 和/players/4
由于 firebase pull 异步工作,您可能需要使用计数器或其他一些机制,以便在拉取最后一个数据时可以继续运行完成代码。
关于android - Firebase 数据扁平化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39356529/
我有一个 TeamCity (9.0.2) 构建配置,其中包含以下工件路径模式: App\Agent\**\bin\%env.Configuration%\** => Deployment\Agent
我在 src 目录中有一个具有嵌套文件结构的项目。到目前为止,我一直在使用 babel --out-dir lib src 。最近我想到了一个想法,让用户直接使用单独的文件,所以基本上我想改造这个结构
我有一个数据库表,其中三列对于这个问题至关重要: 组 ID,将行分组在一起 开始日期 结束日期 我想从此表中创建一个 View ,以便将具有相同分组 ID 的重叠日期间隔展平。 不重叠的日期间隔不得展
我有一个很大的 pandas 数据框,有 8 列和几个 NaN 值: 0 1 2 3 4 5 6 7 8 1 Google, Inc. (Date 11/07/20
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 5 年前。 Improve this ques
我想将 simd_float4x4 或 simd_float3x3 矩阵展平为单个浮点元素数组。 对于常规数组我会使用 let arr = [[1,2,3],[4,5,6],[7,8,9]] prin
我正在寻找一种 Pythonic 方式来获取 OrderedDict 的 .values 的并集,在 折叠组成值的列表之后。我希望结果是一维列表,根据自定义顺序排序。 我在做什么: from coll
这个问题在这里已经有了答案: How do I make a flat list out of a list of lists? (36 个答案) 关闭 9 年前。 所以我目前正在使用 mongoe
我有一个像这样的数组。 [{"title"=>"ga:browser=Internet Explorer", "dimensions"=>[{:browser=>"Internet Explorer"
我正在尝试使用 Tabulator 创建工单列表,数据通过 AJAX url 从工单系统导入为 JSON,如下所示。 { "results": [ {
我有两个函数,每个函数都返回 CompletebleFuture实例,我想 or它们变成一个有序且可短路的 future 。 public CompletableFuture doA(); publi
我需要在 mysql 中用逗号分隔值将非主键列展平为一行。让我们举一个简单的例子。有一个名为 stud_sub 的表,其中 stud_id 和 sub_id 作为复合主键。现在我想要一个表,其中 st
这个问题在这里已经有了答案: Comprehension on a nested iterables? (13 个答案) 关闭 4 个月前。 我最近在寻找一种将嵌套的 Python 列表展平的方法,
我在 C# 中有一个 json 对象(表示为 Newtonsoft.Json.Linq.JObject 对象),我需要将它扁平化为字典。让我用一个例子来说明我的意思: { "name": "t
有人可以帮我进行以下转换吗? 这里是输入的xml: My book 200 big Smith Wallace
在下面的代码中,x 是 Future[Future[Int]] 类型,我需要将其展平为 Future[Int] .这怎么可能? def times(a:Int, b:Int) = Future
我对 R 还很陌生,我正在尝试使用 aggregate对数据帧、每个主题和数据集中的每个指标执行一些时间序列整形。这很好用,但我发现结果不是很容易使用的格式。我希望能够将结果转换回与原始数据帧相同的格
我有一个项目,我需要填写预制的 PDF,我想到的最合乎逻辑的解决方案是将预制的 PDF 制作成 PDF 表单,以便输入值应该放在标签中,然后我可以查看 PDF 中的表单标签,并将它们与值字典对齐。 我
首先,我对 Azure 还很陌生。 我已使用 Web 角色成功将 ASP.NET MVC 3 Web 应用程序部署到 Azure。该应用程序使用 Entity Framework 和 SQL Azur
我试图将 XML 层次结构展平为文本节点,其中输出标记名称是每个文本节点路径上的连字符连接标记。我对 http://www.chilkatsoft.com/xml-samples/bookstore.
我是一名优秀的程序员,十分优秀!