greetings! yes, fetching items from the datastore is expensive, hence
a good reason why you should minimize fetches... using memcache is a
great idea!

poking through the code, there are a small number of minor
optimizations you can make as well:

> def __getUserKey(user,required=False):
>  ret = db.GqlQuery("SELECT * FROM User WHERE user = :1",user.lower
> ()).get()
>  if required and ret == None:

change the clause above to "ret is None" as this comparison is faster.
more info here...

http://mail.python.org/pipermail/tutor/2002-April/013932.html

... but it doesn't mention the performance implications. basically,
it's object value comparison vs. object identity comparison. if you're
just checking to see if both pointers are looking at the same object,
it's faster than having to defer the references to get both objects
just to then compare their values.


>    raise dbException, 'user \''+user+'\' not in database\n'
>  return ret
>
> def __getItems(user):
>  userKey = __getUserKey(user,True)
>
>  t0 = time.time()
>  n_items = 0
>  for item in userKey.items:
>    n_items = n_items + 1

change to augmented assignment, e.g., "n_items += 1"... you save the
extra lookup.


>  logging.debug('got %s items', n_items)
>  logging.debug('getting items took %s ms', 1000*(time.time()-t0))

or, if you just want a count, use count() -- however, i'm guessing
you're more interested in checking entity fetch times over how many
entities you've fetched in a query.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
   http://corepython.com

wesley.j.chun :: [email protected]
developer relations :: google app engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to