I am retrieving several 100+ objects from the data store using the following query
return entity.query (ancestor = ancestorKey) .filter (entity.year = myStartYear) .order (entity.num) .fetch ()
It took a long time to load (in the order of a few seconds).
Trying to find the best way, I created exactly 100 entities, I found that it takes 750 ms to 1000 ms to get 100 objects on the local server, which is important. I'm not sure how to get around one line to make it more efficient!
In a desperate attempt to optimize, I tried
- Deleting part of the order still got the same results
- Removing part of the filter still got the same results
- Removing part of filter & , still got the same results
So, apparently, this is something else. In a desperate attempt, I tried key fetching and then passed the keys to the ndb.get_multi () function :
qKeys = entity.query (ancestor = ancestorKey) .filter (entity.year = myStartYear) .order (entity.num) .fetch (keys_only = True)
return ndb.get_multi (qKeys)
To my surprise, I get better bandwidth! query results are now loaded in 450 ~ 550 ms, which averages ~ 40% .
I'm not sure why this is happening, I would think that the fetch function is already querying entities at the most optimal time.
Question:
Any idea how I can optimize a single query string to load faster?
:
- , fetch , ndb.get_multi() ?