简体   繁体   English

Google数据存储区中查询的复杂性

[英]Complexity of a query in the Google datastore

I have an Android app where users will be able to send private messages to each other. 我有一个Android应用程序,用户可以在其中发送私人消息。 (for instance: A sends a message to B and C and the three of them may comment that message) (例如:A向B和C发送消息,其中三个可以对该消息发表评论)

I use google app engine and the google datastore with Java. 我使用谷歌应用引擎和谷歌的谷歌数据存储。 (framework Objectify) I have created a Member entity and a Message entity which contains a ArrayList<String> field, representing the recipients'ids list. (框架Objectify)我创建了一个Member实体和一个Message实体,它包含一个ArrayList<String>字段,表示recipients'ids列表。 (that is to say the key field of the Member entity) (也就是说Member实体的关键领域)

In order for a user to get all the messages where he is one of the recipients, I was planning on loading each Message entity on the datastore and then select them by checking if the ArrayList<String> field contains the user's id. 为了让用户获取他是其中一个收件人的所有邮件,我计划在数据存储上加载每个Message实体,然后通过检查ArrayList<String>字段是否包含用户的id来选择它们。 However, considering there may be hundred of thousands messages stored, I was wondering if that is even possible and if that wouldn't take too much time? 但是,考虑到可能存储了数十万条消息,我想知道这是否可能,如果这不会花费太多时间?

The time to fetch results from the datastore only relates to the number of Entities retrieved, not to the total number of Entities stored because every query MUST use an index. 从数据存储区获取结果的时间仅与检索到的实体数有关,而与存储的实体总数无关,因为每个查询必须使用索引。 That's exactly what makes the datastore so scalable. 这正是使数据存储如此可扩展的原因。

You will have to limit the number of messages retrieved per call and use a Cursor to fetch the next batch. 您必须限制每次调用检索的消息数,并使用Cursor获取下一批。 You can send the cursor over to the Android client by converting it to a websafe string , so the client can indicate the starting point for the next request. 您可以通过将光标转换为网络安全字符串将光标发送到Android客户端,以便客户端可以指示下一个请求的起始点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM