Hi

Why are doing the loop on the results from the fetch

>     for a in MyModel.all().filter('somekey =', x).fetch(1000):
>         result.append(a)

will give you the same as

result = MyModel.all().filter('somekey =', x).fetch(1000)

A further loop after the fetch is entirely redundant.

The accumulated time to fetch each entity will be the same, but
fetching each item
one at a time will add an additional latency getting each item one by
one.  There are quite a few articles
about this written by various google people

T



On May 10, 11:26 am, Adrian Holovaty <[email protected]> wrote:
> On May 9, 9:58 pm, Adrian Holovaty <[email protected]> wrote:
>
> > > Also I assume you do a fetch on the query rather than iterating of the
> > > result (fetch is much quicker).
>
> > Oh, we could be onto something here. I'm iterating over the result,
> > not using fetch, because I was under the impression fetch() was only
> > for a limited number of records. Are you saying that I could pass a
> > dummy huge number to fetch(), like fetch(1000000), and it would be
> > faster than iterating? If so, that would be an easy win.
>
> I just spent a bit of time testing this, and I wasn't able to get a
> measurable difference between fetch() and iterating. Here are the
> three approaches I tried:
>
>     for a in MyModel.all().filter('somekey =', x):
>         result.append(a)
>
>     for a in MyModel.all().filter('somekey =', x).fetch(10000):
>         result.append(a)
>
>     for a in list(MyModel.all().filter('somekey =', x).fetch(10000)):
>         result.append(a)
>
> Each of those had 6107api_cpu_ms in my logs. The values for cpu_ms
> weren't significantly different. Am I misunderstanding your comment
> about fetch()? (I *do* want to get all results, not just a limited
> subset.)
>
> Adrian
>
> --
> 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 
> athttp://groups.google.com/group/google-appengine?hl=en.

-- 
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