Created
September 21, 2010 16:52
-
-
Save sahid/590028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
# Because if ref_keys has a None value, | |
# db.get raise a BadArgumentError exception. | |
for (i, v) in enumerate (ref_keys): | |
if v is None: | |
del ref_keys[i] | |
del fields[i] | |
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