It's very powerful to be able to do things like profile.user.email but
as you say such call will cause an extra datastore query (unless
already in memory). I have changed a part in my code which is called
frequently and replaced message.account.X with message.X which
requires duplication of X to be stored but which significantly
improves speed/CPU cost performance.

On Nov 18, 8:44 pm, Rafal Jonca <[EMAIL PROTECTED]> wrote:
> I think you have the same problem that I had -> too many queries to
> the datastore.
>
> I'm pretty sure that {{profile.user.email}} and similar are giving you
> too many queries, because do not have joins.
> I assume that in profile the user is a ReferenceProperty.
>
> You fetch 100 profiles -> 1 query
> Getting user for those 100 profiles -> 100 queries
>
> GAE is cahcing the ReferenceProperty AFAIK. If it wouldn't be the
> case, you could get even 500 queries.
>
> You need to redesing this loop, propable getting profiles and then
> getting all users with another, but one query.
>
> --
> Rafal Jonca
> Blog:http://www.rafaljonca.org/
>
> On 18 Lis, 09:56, Bigdude <[EMAIL PROTECTED]> wrote:
>
> > Google app engine tells me to optimize this code. Anybody any ideas
> > what I could do?
>
> > def index(request):
> >     user = users.get_current_user()
> >     return base.views.render('XXX.html',
> >                  dict(profiles=Profile.gql("").fetch(limit=100),
> > user=user))
>
> > And later in the template I do:
>
> > {% for profile in profiles %}
> >   <a href="/profile/{{profile.user.email}}/"><img
> > src="{{profile.gravatarUrl}}"></a>
> >   <a href="/profile/{{profile.user.email}}/">
> > {{ profile.user.nickname }}</a>
> >   <br/>{{ profile.shortDisplay }}
>
> > Where the methods used are:
>
> > def shortDisplay(self):
> >     return "%s/day; %s/week; %s days" % (self.maxPerDay,
> > self.maxPerWeek, self.days)
>
> > def gravatarUrl(self):
> >     email = self.user.email().lower()
> >     default = "..."
> >     gravatar_url = "http://www.gravatar.com/avatar.php?";
> >     gravatar_url += urllib.urlencode({'gravatar_id':hashlib.md5
> > (email).hexdigest(),
> >         'default':default, 'size':"64"})
> >     return gravatar_url
>
>
--~--~---------~--~----~------------~-------~--~----~
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