I am querying the datastore that looks something like this:
Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY,
"SELECT * FROM " + kind
+ " WHERE Location = place").build();
results = datastore.run(query);
The results are being stored in a QueryResults<Entity> results;
Then I loop through the results and extract the data I need.
The kind has around 10000 Entities in it and I am extracting them all.
while (results.hasNext()) {
Entity result = results.next();
....
}
Is takes 10-ish seconds for this to happen. Is there a way to reduce this time? I know that looping through results is causing the slowdown.
(a) Make sure you set the batch size to 500 when you run your query. By default, it's 10.
(b) Optimize your own code inside the loop. For example:
Entity result;
while (results.hasNext()) {
result = results.next();
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With