Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created August 25, 2011 06:00
Show Gist options
  • Save Arachnid/1170080 to your computer and use it in GitHub Desktop.
Save Arachnid/1170080 to your computer and use it in GitHub Desktop.
def prefetch_refprops(entities, *props):
fields = [(entity, prop) for entity in entities for prop in props]
ref_keys = set(prop.get_value_for_datastore(x) for x, prop in fields)
ref_keys.discard(None)
ref_entities = dict((x.key(), x) for x in db.get(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