Skip to content

Instantly share code, notes, and snippets.

@d6veteran
Created January 26, 2011 20:30
Show Gist options
  • Save d6veteran/797387 to your computer and use it in GitHub Desktop.
Save d6veteran/797387 to your computer and use it in GitHub Desktop.
Dereference Reference Properties in Batch Get()
def prefetch_refprops(entities, *props):
fields = [(entity, prop) for entity in entities for prop in props]
ref_keys = [prop.get_value_for_datastore(x) for x, prop in fields]
ref_entities = dict((x.key(), x) for x in db.get(set(ref_keys)))
for (entity, prop), ref_key in zip(fields, ref_keys):
prop.__set__(entity, ref_entities[ref_key])
return entities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment