Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Created August 5, 2011 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewxhill/1127799 to your computer and use it in GitHub Desktop.
Save andrewxhill/1127799 to your computer and use it in GitHub Desktop.
"""
Another thought
The use of indexes can be super useful as it avoids serialization of all the data
by doing key only queries. Then, using the key returned to pull the parent which
would be the full set of data. So, something like this
"""
class CellIndex(db.Model):
#parent = Cell
z = db.IntegerProperty(required=True)
x = db.IntegerProperty(required=True)
y = db.IntegerProperty(required=True)
parent_id = db.StringProperty()
report = db.ReferenceProperty(Report)
ndfi_low = db.FloatProperty(default=0.2)
ndfi_high = db.FloatProperty(default=0.3)
ndfi_change_value = db.FloatProperty(default=0.0)
done = db.BooleanProperty(default=False);
last_change_by = db.UserProperty()
last_change_on = db.DateTimeProperty(auto_now=True)
class Cell(db.Model):
data = db.BlobStore() #where this is a pickled json object of all the data
def Example():
q = CellIndex.all(keys_only = True).filter('ndfi_low =', 30).fetch(10)
for r in q:
print json.dumps(r.parent.data)
"""
So what we do here is skip the serialization of all the properties
of the CellIndex because it will use the automatic index on ndfi_low,
then we just grab the returned result parents and serialize one single object
"""
"""Totally just wrote that off the top of my head so probably error full.
This particular example may have 0 benefit, but you can see where it is goin"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment