I want to pull all the objects from my list of their keys. Is there a better way than how I'm doing it now?
list_of_objs = []
for obj_key in list_of_keys:
this_obj = db.get(obj.key)
list_of_objs.append(this_obj)
According to documentation db.get may accept list of keys and fetch them in a single batch, which will be much faster.
list_of_objects = db.get(list_of_keys)
list_of_entities = ndb.get_multi(list_of_keys)
Jun 2, 2014 at 18:19
Not familiar with your specific application (specifically the db.get) but you may want to consider a list comprehension.
list_of_objs = [db.get(obj.key) for obj in list_of_keys]
You could use the IN operator
query = db.Query()
list_of_objs = query.filter('__key__ IN', ','.join(list_of_keys))
this (or something similar) should do the job
According to the docs such queries are possible