- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在构建一个大量使用 Firebase 数据库的 Android 应用。
在数据库中,我有一个名为 RootNode 的节点,它包含 100 个子节点。 RootNode 的每个子节点都有自己的子节点(每个子节点有 30 到 60 个),每个子节点都有自己的键值属性(因此,我们正在谈论每个子节点的大量数据)。
客户端,我将 RootNode 的所有子节点的 key 存储在 List<String> list
中.通过遍历此列表,我向 RootNode 的每个子节点添加了一个 ValueEventListener。
// Loop through the children of RootNode.
for (final String keyOfChildNode: list) { // list contains the keys of all the children nodes of RootNode.
Log.d(TAG, "Adding ValueEventListener to child node: " + keyOfChildNode);
// Set a ValueEventListener to child node.
RootNodeReference.child(keyOfChildNode).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Datasnapshot of child has been retrieved.
Log.d(TAG, "Datasnapshot retrieved for child node: " + keyOfChildNode);
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Report error.
}
});
}
这是控制台输出:
Adding ValueEventListener to child node: keyChildNode001
Adding ValueEventListener to child node: keyChildNode002
Adding ValueEventListener to child node: keyChildNode003
Adding ValueEventListener to child node: keyChildNode004
Adding ValueEventListener to child node: keyChildNode005
Adding ValueEventListener to child node: keyChildNode006
Adding ValueEventListener to child node: keyChildNode007
Adding ValueEventListener to child node: keyChildNode008
Adding ValueEventListener to child node: keyChildNode009
Adding ValueEventListener to child node: keyChildNode010
Adding ValueEventListener to child node: keyChildNode011
Adding ValueEventListener to child node: keyChildNode012
Adding ValueEventListener to child node: keyChildNode013
Adding ValueEventListener to child node: keyChildNode014
Adding ValueEventListener to child node: keyChildNode015
Adding ValueEventListener to child node: keyChildNode016
Adding ValueEventListener to child node: keyChildNode017
Adding ValueEventListener to child node: keyChildNode018
Adding ValueEventListener to child node: keyChildNode019
Adding ValueEventListener to child node: keyChildNode020
Adding ValueEventListener to child node: keyChildNode021
Adding ValueEventListener to child node: keyChildNode022
Adding ValueEventListener to child node: keyChildNode023
Adding ValueEventListener to child node: keyChildNode024
Adding ValueEventListener to child node: keyChildNode025
Adding ValueEventListener to child node: keyChildNode026
Adding ValueEventListener to child node: keyChildNode027
Adding ValueEventListener to child node: keyChildNode028
Adding ValueEventListener to child node: keyChildNode029
Adding ValueEventListener to child node: keyChildNode030
Adding ValueEventListener to child node: keyChildNode031
Adding ValueEventListener to child node: keyChildNode032
Adding ValueEventListener to child node: keyChildNode033
Adding ValueEventListener to child node: keyChildNode034
Adding ValueEventListener to child node: keyChildNode035
Adding ValueEventListener to child node: keyChildNode036
Adding ValueEventListener to child node: keyChildNode037
Adding ValueEventListener to child node: keyChildNode038
Adding ValueEventListener to child node: keyChildNode039
Adding ValueEventListener to child node: keyChildNode040
Adding ValueEventListener to child node: keyChildNode041
Adding ValueEventListener to child node: keyChildNode042
Adding ValueEventListener to child node: keyChildNode043
Adding ValueEventListener to child node: keyChildNode044
Adding ValueEventListener to child node: keyChildNode045
Adding ValueEventListener to child node: keyChildNode046
Adding ValueEventListener to child node: keyChildNode047
Adding ValueEventListener to child node: keyChildNode048
Adding ValueEventListener to child node: keyChildNode049
Adding ValueEventListener to child node: keyChildNode050
Adding ValueEventListener to child node: keyChildNode051
Adding ValueEventListener to child node: keyChildNode052
Adding ValueEventListener to child node: keyChildNode053
Adding ValueEventListener to child node: keyChildNode054
Adding ValueEventListener to child node: keyChildNode055
Adding ValueEventListener to child node: keyChildNode056
Adding ValueEventListener to child node: keyChildNode057
Adding ValueEventListener to child node: keyChildNode058
Adding ValueEventListener to child node: keyChildNode059
Adding ValueEventListener to child node: keyChildNode060
Adding ValueEventListener to child node: keyChildNode061
Adding ValueEventListener to child node: keyChildNode062
Adding ValueEventListener to child node: keyChildNode063
Adding ValueEventListener to child node: keyChildNode064
Adding ValueEventListener to child node: keyChildNode065
Adding ValueEventListener to child node: keyChildNode066
Adding ValueEventListener to child node: keyChildNode067
Adding ValueEventListener to child node: keyChildNode068
Adding ValueEventListener to child node: keyChildNode069
Adding ValueEventListener to child node: keyChildNode070
Adding ValueEventListener to child node: keyChildNode071
Adding ValueEventListener to child node: keyChildNode072
Adding ValueEventListener to child node: keyChildNode073
Adding ValueEventListener to child node: keyChildNode074
Adding ValueEventListener to child node: keyChildNode075
Adding ValueEventListener to child node: keyChildNode076
Adding ValueEventListener to child node: keyChildNode077
Adding ValueEventListener to child node: keyChildNode078
Adding ValueEventListener to child node: keyChildNode079
Adding ValueEventListener to child node: keyChildNode080
Adding ValueEventListener to child node: keyChildNode081
Adding ValueEventListener to child node: keyChildNode082
Adding ValueEventListener to child node: keyChildNode083
Adding ValueEventListener to child node: keyChildNode084
Adding ValueEventListener to child node: keyChildNode085
Adding ValueEventListener to child node: keyChildNode086
Adding ValueEventListener to child node: keyChildNode087
Adding ValueEventListener to child node: keyChildNode088
Adding ValueEventListener to child node: keyChildNode089
Adding ValueEventListener to child node: keyChildNode090
Adding ValueEventListener to child node: keyChildNode091
Adding ValueEventListener to child node: keyChildNode092
Adding ValueEventListener to child node: keyChildNode093
Adding ValueEventListener to child node: keyChildNode094
Adding ValueEventListener to child node: keyChildNode095
Adding ValueEventListener to child node: keyChildNode096
Adding ValueEventListener to child node: keyChildNode097
Adding ValueEventListener to child node: keyChildNode098
Adding ValueEventListener to child node: keyChildNode099
Adding ValueEventListener to child node: keyChildNode100
Datasnapshot retrieved for child node: keyChildNode001
Datasnapshot retrieved for child node: keyChildNode002
Datasnapshot retrieved for child node: keyChildNode003
Datasnapshot retrieved for child node: keyChildNode004
Datasnapshot retrieved for child node: keyChildNode005
Datasnapshot retrieved for child node: keyChildNode006
Datasnapshot retrieved for child node: keyChildNode007
Datasnapshot retrieved for child node: keyChildNode008
Datasnapshot retrieved for child node: keyChildNode009
Datasnapshot retrieved for child node: keyChildNode010
Datasnapshot retrieved for child node: keyChildNode011
Datasnapshot retrieved for child node: keyChildNode012
Datasnapshot retrieved for child node: keyChildNode013
Datasnapshot retrieved for child node: keyChildNode014
Datasnapshot retrieved for child node: keyChildNode015
Datasnapshot retrieved for child node: keyChildNode016
Datasnapshot retrieved for child node: keyChildNode017
Datasnapshot retrieved for child node: keyChildNode018
Datasnapshot retrieved for child node: keyChildNode019
Datasnapshot retrieved for child node: keyChildNode020
Datasnapshot retrieved for child node: keyChildNode021
Datasnapshot retrieved for child node: keyChildNode022
Datasnapshot retrieved for child node: keyChildNode023
Datasnapshot retrieved for child node: keyChildNode024
Datasnapshot retrieved for child node: keyChildNode025
Datasnapshot retrieved for child node: keyChildNode026
Datasnapshot retrieved for child node: keyChildNode027
Datasnapshot retrieved for child node: keyChildNode028
Datasnapshot retrieved for child node: keyChildNode029
Datasnapshot retrieved for child node: keyChildNode030
Datasnapshot retrieved for child node: keyChildNode031
Datasnapshot retrieved for child node: keyChildNode032
Datasnapshot retrieved for child node: keyChildNode033
Datasnapshot retrieved for child node: keyChildNode034
Datasnapshot retrieved for child node: keyChildNode035
Datasnapshot retrieved for child node: keyChildNode036
Datasnapshot retrieved for child node: keyChildNode037
Datasnapshot retrieved for child node: keyChildNode038
Datasnapshot retrieved for child node: keyChildNode039
Datasnapshot retrieved for child node: keyChildNode040
Datasnapshot retrieved for child node: keyChildNode041
Datasnapshot retrieved for child node: keyChildNode042
Datasnapshot retrieved for child node: keyChildNode043
Datasnapshot retrieved for child node: keyChildNode044
Datasnapshot retrieved for child node: keyChildNode045
Datasnapshot retrieved for child node: keyChildNode046
Datasnapshot retrieved for child node: keyChildNode047
Datasnapshot retrieved for child node: keyChildNode048
Datasnapshot retrieved for child node: keyChildNode049
Datasnapshot retrieved for child node: keyChildNode050
Datasnapshot retrieved for child node: keyChildNode051
Datasnapshot retrieved for child node: keyChildNode052
Datasnapshot retrieved for child node: keyChildNode053
Datasnapshot retrieved for child node: keyChildNode054
Datasnapshot retrieved for child node: keyChildNode055
Datasnapshot retrieved for child node: keyChildNode056
Datasnapshot retrieved for child node: keyChildNode057
Datasnapshot retrieved for child node: keyChildNode058
Datasnapshot retrieved for child node: keyChildNode059
Datasnapshot retrieved for child node: keyChildNode060
Datasnapshot retrieved for child node: keyChildNode061
Datasnapshot retrieved for child node: keyChildNode062
Datasnapshot retrieved for child node: keyChildNode063
Datasnapshot retrieved for child node: keyChildNode064
Datasnapshot retrieved for child node: keyChildNode065
Datasnapshot retrieved for child node: keyChildNode066
Datasnapshot retrieved for child node: keyChildNode067
Datasnapshot retrieved for child node: keyChildNode068
Datasnapshot retrieved for child node: keyChildNode069
Datasnapshot retrieved for child node: keyChildNode070
Datasnapshot retrieved for child node: keyChildNode071
Datasnapshot retrieved for child node: keyChildNode072
Datasnapshot retrieved for child node: keyChildNode073
Datasnapshot retrieved for child node: keyChildNode074
Datasnapshot retrieved for child node: keyChildNode075
Datasnapshot retrieved for child node: keyChildNode076
Datasnapshot retrieved for child node: keyChildNode077
Datasnapshot retrieved for child node: keyChildNode078
Datasnapshot retrieved for child node: keyChildNode079
Datasnapshot retrieved for child node: keyChildNode080
Datasnapshot retrieved for child node: keyChildNode081
Datasnapshot retrieved for child node: keyChildNode082
Datasnapshot retrieved for child node: keyChildNode083
Datasnapshot retrieved for child node: keyChildNode084
Datasnapshot retrieved for child node: keyChildNode085
Datasnapshot retrieved for child node: keyChildNode086
Datasnapshot retrieved for child node: keyChildNode087
Datasnapshot retrieved for child node: keyChildNode088
Datasnapshot retrieved for child node: keyChildNode089
Datasnapshot retrieved for child node: keyChildNode090
Datasnapshot retrieved for child node: keyChildNode091
Datasnapshot retrieved for child node: keyChildNode092
Datasnapshot retrieved for child node: keyChildNode093
Datasnapshot retrieved for child node: keyChildNode094
Datasnapshot retrieved for child node: keyChildNode095
Datasnapshot retrieved for child node: keyChildNode096
Datasnapshot retrieved for child node: keyChildNode097
Datasnapshot retrieved for child node: keyChildNode098
Datasnapshot retrieved for child node: keyChildNode099
Datasnapshot retrieved for child node: keyChildNode100
有一件事让我感到惊讶:由于添加到子引用的 ValueEventListeners 本质上是异步的,我预计快照将以随机顺序检索(不一定与 ValueEventListeners 的顺序相同)添加)。但控制台输出显示快照是按照将 ValueEventListeners 添加到每个子节点的顺序检索的。
以这种“有序”的方式检索快照是否正常?如果是,考虑到监听器的异步性质,这怎么可能?提前谢谢你。
最佳答案
这确实是预期的行为。
Firebase 数据库客户端通过单个套接字连接与其服务器进行通信。此套接字用于客户端和数据库服务器之间的所有通信。
当您请求 100 条记录时,所有请求都按照您进行调用的顺序通过这个单一连接发送。然后服务器以相同的顺序执行请求并以相同的顺序返回结果。
这称为流水线:通过单个连接发送多个请求并按顺序返回结果。我之前在这里回答了更多:Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly
关于android - Firebase Database Android - 来自多个 ValueEventListeners 的快照检索顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41572610/
我们使用 Azure 弹性池,生成多个客户端数据库和一个引用客户端数据库的主数据库。 我们已经拥有多个数据库,并且正在开发新版本的代码。我们使用 EF6 代码优先。当我们对模型进行更改(添加属性)时,
我们使用 Azure 弹性池,生成多个客户端数据库和一个引用客户端数据库的主数据库。 我们已经拥有多个数据库,并且正在开发新版本的代码。我们使用 EF6 代码优先。当我们对模型进行更改(添加属性)时,
我希望将一些信息分发到不同的机器上,以便在没有任何网络开销的情况下实现高效和极快的访问。数据存在于关系模式中,实体之间的关系是“加入”的要求,但根本不是写入数据库的要求(它会离线生成)。 我非常相信
我使用 GrapheneDB 来托管我的 neo4j 数据库 (db)。 问题 我有 N客户并且正在寻找自动分离他们的内容(他们独特的数据库)的方法,以便: 它不重叠数据 操作速度不受影响。 选项 1
当服务器开始工作(Tomcat)时,日志显示此错误: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid b
我在 Oracle 数据库实例中按以下方式创建了一个触发器。 CREATE OR REPLACE TRIGGER after_logon_on_database AFTER LOGON ON DATA
原谅我的无知,我是数据库约定的初学者。 这是我的 SQLite 代码:(由我的数据库浏览器自动生成) CREATE TABLE `ResearchItems` ( `ID` INTEGER NO
是的是的是的,我已经在整个互联网上搜索过这个问题。一些结果发现,甚至来自 Stackoverflow。但是他们中的大多数人说“你应该自动加载数据库”,或者“parent::__construct();
我正在创建一个 Mac 应用程序,它将一些数据保存到 SQLite 数据库中。问题是:当我关闭数据库并再次打开时,数据不存在了。这是我的代码: NSString *sql = [NSString st
我正在建立一个网站,我打算发布各种帖子,比如教程、文章等。我打算用 php 来管理它,但是当涉及到存储每个帖子的内容时,将要显示的文本,更好的选择是:使用单独的文本文件还是将其添加为数据库中的每个条目
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
对不起,这个关键字对我来说没有任何意义...有人可以给我一个定义吗? 提前致谢... 最佳答案 这是一个品牌。 http://pervasive.com/这是他们的数据库产品的链接 http://ww
我已经在 docker 版本 1.10.1 的 docker 镜像中安装了 PostgreSQL 9.4.6。根据这张官方图片: https://github.com/docker-library/p
当我的 android 应用程序尝试读取 android 短信数据库时,我遇到了这个崩溃。读取android短信数据库的代码类似于下面的代码 fragment : String SMS_URI = "
我有一个 public kit repo,我推送了 v1.0.3 并具有以下结构 go -database --database.go --go.mod --go.sum 我需要它 require g
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我们正在使用MySQL数据库在Go中创建一个Web应用程序。我们的用户一次只能拥有一个活跃的客户端。就像Spotify一样,您一次只能在一台设备上听音乐。为此,我制作了一个映射,将用户ID和作为其值的
我已经尝试在 PostgreSQL 中创建数据库好几天了,遇到了几个问题,但似乎卡住了。 我在 PostgreSQL 中手动创建了一个名为 postgres_development 的数据库,因为 b
我正在创建一个 iMessage 应用程序,它需要连接到与我的常规应用程序相同的数据库。 我调用 FirebaseApp.configure() 并对用户进行身份验证,但出于某种原因,在所有 Data
就像std::unordered_map但所有数据都应存储在磁盘上而不是内存中。 按照我的理解,应该做两部分:索引和存储。我已经学习了一些关于索引的数据结构,比如 Linear-Hash 或 B-Tr
我是一名优秀的程序员,十分优秀!