[google-appengine] Re: What is the fastest way to check if an item is in the datastore?

2009-01-12 Thread Alexander Kojevnikov

> Is there a faster/better way? Do I need to do anything with indexes to
> make this query better?
>
You can replace fetch(1) with get(), which is essentially the same.
Other than that, if you know your entity's id/key_name, it's slightly
faster to fetch it using get_by_id() or get_by_key_name().
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is the fastest way to check if an item is in the datastore?

2009-01-12 Thread Dan Sanderson
If you don't need the entity, count(1) would be faster than fetch(1) or
get().
-- Dan

On Mon, Jan 12, 2009 at 12:54 PM, SM  wrote:

>
>
> I have a simple model like this:
>
> class MyModel(db.Model):
>  prop = db.StringProperty()
>  active = db.BooleanProperty(default=False)
>
> Given an input string, s, I'd like to know if it is in the datastore.
> Would this be the best way to check?
>
> if MyModel.gql("WHERE prop = :1 AND active = True", s).fetch(1):
>  print "Found"
> else:
>  print "Not found"
>
> Is there a faster/better way? Do I need to do anything with indexes to
> make this query better?
>
> >
>

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



[google-appengine] Re: What is the fastest way to check if an item is in the datastore?

2009-01-12 Thread ryan

+1 to the responses.

just to clarify, for the purposes of the archives. in case there's
confusion between the two get() methods: Model.get()/db.get() are
generally the fastest, modulo the size of the entity. Query.count(1)
will be in the same ballpark, usually a little slower, but faster if
the entity is big. Query.get(), and Query.fetch(1) are slower still,
and basically the same.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is the fastest way to check if an item is in the datastore?

2009-01-12 Thread SM

Thank you to everyone for the responses.

If I understand correctly, for my exampe I should use

if MyModel.gql("WHERE prop = :1 AND active = True", s).count(1):
  print "Found"
else:
  print "Not found"


On Jan 12, 5:52 pm, ryan  wrote:
> +1 to the responses.
>
> just to clarify, for the purposes of the archives. in case there's
> confusion between the two get() methods: Model.get()/db.get() are
> generally the fastest, modulo the size of the entity. Query.count(1)
> will be in the same ballpark, usually a little slower, but faster if
> the entity is big. Query.get(), and Query.fetch(1) are slower still,
> and basically the same.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is the fastest way to check if an item is in the datastore?

2009-01-12 Thread kang
you get it

On Tue, Jan 13, 2009 at 10:30 AM, SM  wrote:

>
> Thank you to everyone for the responses.
>
> If I understand correctly, for my exampe I should use
>
> if MyModel.gql("WHERE prop = :1 AND active = True", s).count(1):
>   print "Found"
> else:
>  print "Not found"
>
>
> On Jan 12, 5:52 pm, ryan 
> >
> wrote:
> > +1 to the responses.
> >
> > just to clarify, for the purposes of the archives. in case there's
> > confusion between the two get() methods: Model.get()/db.get() are
> > generally the fastest, modulo the size of the entity. Query.count(1)
> > will be in the same ballpark, usually a little slower, but faster if
> > the entity is big. Query.get(), and Query.fetch(1) are slower still,
> > and basically the same.
> >
>


-- 
Stay hungry,Stay foolish.

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