Ah, thanks.

>You're also introducing a potential synchronization/concurrency issue.

What do you mean?


On Apr 6, 9:08 pm, "Nick Johnson (Google)" <[email protected]>
wrote:
> Hi Jordon,
>
> Calling .get() and checking if the result is None is more efficient. Calling
> count executes the query, and calling get executes it again, so doing it
> that way you're pointlessly duplicating the effort. You're also introducing
> a potential synchronization/concurrency issue.
>
> -Nick Johnson
>
>
>
>
>
>
>
>
>
> On Thu, Apr 7, 2011 at 9:49 AM, Jordon Wii <[email protected]> wrote:
> > Hi guys,
> > Which of the following is more efficient:
>
> > Using Query.count(1) to test, then using .get() if there is a result:
> > -------
> > q = MyModel.all().filter("field =", value)
> > count = q.count(1)
>
> > if count:
> >    result = q.get()
> >    do_stuff(result)
> > else:
> >    create_entity()
> > --------
>
> > Or just calling .get():
> > -------
> > result = MyModel.all().filter("field =", value).get()
>
> > if result:
> >    do_stuff(result)
> > else:
> >    create_entity()
> > -----
>
> > The first one saves resources by not fetching the entity unless it has
> > to, whereas the second one calls .get() no matter what, but doesn't
> > use .count()
>
> > --
> > 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.
>
> --
> Nick Johnson, Developer Programs Engineer, 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