Question

I have a list of key names that I want to bulk fetch (the key names are stored in a StringListProperty attached to an entity). My general plan was to do:

usernames = userrefInstance.users # A collection of strings on another 
model. 
keys = [Key.from_path('User', key_name) for username in usernames] 
users = db.get(keys)

My questions does Key.from_path hit the datastore? I am trying to be as quick as possible and if Key.from_path hits the data store I need to work another way to store a collection of keys - I don't particularly want to store the Key object in a list property as I also provide user friendly queries across the StringListPropererties.

Was it helpful?

Solution

After digging and questions on another group, it turns out that:

keys are entirely determined by the app ID and the path, so there's no need to access the datastore for this. - Nick Johnson

Or you can also use a List of db.Key

OTHER TIPS

The parameters you pass to Key.from_path() contain all the information necessary to build the unique key so there is no need for it to hit the datastore.

Each entity in the Datastore has a key that uniquely identifies it. The key consists of the following components:

  1. The kind of the entity, which categorizes it for the purpose of Datastore queries
  2. An identifier for the individual entity, which can be either
    • a key name string
    • an integer numeric ID
  3. An optional ancestor path locating the entity within the Datastore hierarchy

source: https://developers.google.com/appengine/docs/python/datastore/entities

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top