Reputation: 169
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?
Upvotes: 6
Views: 220
Reputation: 6566
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.
Upvotes: 1