models - Google App Engine writes painfully slow - how to fix -



models - Google App Engine writes painfully slow - how to fix -

i have pretty simple models need optimize writes app engine using python painfully slow. here models (example not actual)

class library(db.model): name = db.stringproperty() books = db.listproperty(db.key) #usually between 20 - 200 items class book(db.model): author = db.referenceproperty(author) class author(db.model): name = db.stringproperty() def add_library(books): library = library(name="bob's") book in books: lbook = book() author = author(name="tom") author.put() lbook.author = author lbook.put() library.books.append(lbook) library.put()

this takes between 8 20 seconds insert 1 library, normal? how can optimize more efficient

the problem info model proposed here. cannot have big number of list of keys on 1 side of relationship, described in article - http://code.google.com/appengine/articles/modeling.html

also, for-loop in code segment inserting library record inserts authors , books sequentially. assuming 40ms each datastore put(), , assuming have 50 books , 50 authors, take 4 seconds, long time! , library record gets created.

instead of having list of books on library side, can define models follows:

class library(db.model): name = db.stringproperty() class book(db.model): author = db.referenceproperty(author) library = db.referenceproperty(library, collection_name = 'books')

in case, books define library belongs to. can create library once, , reference books it. when want fetch books, can do

for book in my_library.books: // books

it still take 40ms entering each book, atleast can come in books independently , reference library, has been created.

google-app-engine models

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -