Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. (for instance: A sends a message to B and C and the three of them may comment that message)

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. (that is to say the key field of the Member entity)

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. 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?

like image 699
Gannicus Avatar asked May 15 '15 11:05

Gannicus


People also ask

What are the differences between big query and Datastore?

Datastore is designed to support transactional workloads, such as the backend for a web application. It's optimized for small transactions that read or write a limited number of rows per operation, with strong consistency guarantees. BigQuery is designed for analytic workloads.

What is the query language we can use with Datastore?

The Python Datastore API provides two classes for preparing and executing queries: Query uses method calls to prepare the query. GqlQuery uses a SQL-like query language called GQL to prepare the query from a query string.

How can you reduce latency when adding expenses to Cloud Datastore?

How can you reduce latency when adding expenses to Cloud Datastore? Use a batch operation to add multiple entities in one request. An employee can have multiple expense exports and each expense report can have multiple expenses.

What type of database is Google Datastore?

Datastore is a highly scalable NoSQL database for your web and mobile applications.


1 Answers

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. 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.

like image 155
koma Avatar answered Oct 01 '22 14:10

koma