[google-appengine] Re: sort on _key_ out of order

2009-04-19 Thread David Symonds

On Sun, Apr 19, 2009 at 2:39 AM, David Wilson
david.wil...@entertainmentcloud.com wrote:

 I wasnt using a datetime just to save a bit of space, but i can see i
 need to know to guarantee ordering, or if i want to do ordered paging
 via key i would need to handle key creation myself to make sure they
 are in order.

Unless you are storing a truly huge number of entities (at least
millions), I don't think the extra space should be an issue. The
datastore is really geared towards you adding properties as needed for
exactly this sort of thing.


Dave.

--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread 风笑雪
Key isn't automatic plus 1 when you put a entity.Sometimes it will add 1000
(or some other value), and then back to the ordinary value.

You can check the document about entity's id.

2009/4/18 David Wilson david.wil...@entertainmentcloud.com




 Hi,

 Our myspace application is now running live with an app engine back
 end, but im seeing a few out of order comment and event lists.

 I've tracked the issue to the fact were using a sort on _key_ to order
 the data by date,

 But new data being put into the datastore does not seem to be given id
 values that are larger then the data that is already in there (same
 Model).

 ie:

 ID:6143 Date:2009-04-18 04:53:16.961484
 ID:10009 Date:2009-04-18 00:29:37.483112

 Is this expected behaviour? and thus do i need to always give a
 key_name to guarantee order? this creates scaling issues for order
 counter (which is probably why its not in order in the backend :) )


 Thanks

 David.
 


--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread David Symonds

On Sat, Apr 18, 2009 at 3:21 PM, David Wilson
david.wil...@entertainmentcloud.com wrote:

 Is this expected behaviour? and thus do i need to always give a
 key_name to guarantee order? this creates scaling issues for order
 counter (which is probably why its not in order in the backend :) )

Keys are only guaranteed to be unique, not sequential or in order:
  
http://code.google.com/appengine/docs/python/datastore/keysandentitygroups.html#Paths_and_Key_Uniqueness

What is wrong with giving your models a timestamp property (with
auto_now_add=True), and sorting by that?


Dave.

--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread David Wilson


thanks! i missed that in the docs :)

I wasnt using a datetime just to save a bit of space, but i can see i
need to know to guarantee ordering, or if i want to do ordered paging
via key i would need to handle key creation myself to make sure they
are in order.

This becomes harder in one case for me as users can create designs
that need to be paged through in creation order. There will be too
much contention on a glodal counter for this, so i guess an offset
page on date is the best i can do for now. Or just not worry when some
'new designs' are out of order.



On Apr 18, 2:20 am, David Symonds dsymo...@gmail.com wrote:
 On Sat, Apr 18, 2009 at 3:21 PM, David Wilson

 david.wil...@entertainmentcloud.com wrote:
  Is this expected behaviour? and thus do i need to always give a
  key_name to guarantee order? this creates scaling issues for order
  counter (which is probably why its not in order in the backend :) )

 Keys are only guaranteed to be unique, not sequential or in order:
  http://code.google.com/appengine/docs/python/datastore/keysandentityg...

 What is wrong with giving your models a timestamp property (with
 auto_now_add=True), and sorting by that?

 Dave.
--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread 风笑雪
I use this code to keep an id:

class M(db.Model):
  id = db.IntegerProperty()
  time = db.DateTimeProperty(auto_now_add=True)
   @staticmethod
   def max_id():
maxID = memcache.get('MaxID')
if maxID:
  return maxID
messages = Message.all()
messages.order(-id)
message = messages.get()
if message:
  return message.id
else:
  return 0

entity = M()
entity.id = M.maxID + 1
entity.put()

2009/4/19 David Wilson david.wil...@entertainmentcloud.com



 thanks! i missed that in the docs :)

 I wasnt using a datetime just to save a bit of space, but i can see i
 need to know to guarantee ordering, or if i want to do ordered paging
 via key i would need to handle key creation myself to make sure they
 are in order.

 This becomes harder in one case for me as users can create designs
 that need to be paged through in creation order. There will be too
 much contention on a glodal counter for this, so i guess an offset
 page on date is the best i can do for now. Or just not worry when some
 'new designs' are out of order.



 On Apr 18, 2:20 am, David Symonds dsymo...@gmail.com wrote:
  On Sat, Apr 18, 2009 at 3:21 PM, David Wilson
 
  david.wil...@entertainmentcloud.com wrote:
   Is this expected behaviour? and thus do i need to always give a
   key_name to guarantee order? this creates scaling issues for order
   counter (which is probably why its not in order in the backend :) )
 
  Keys are only guaranteed to be unique, not sequential or in order:
   http://code.google.com/appengine/docs/python/datastore/keysandentityg.
 ..
 
  What is wrong with giving your models a timestamp property (with
  auto_now_add=True), and sorting by that?
 
  Dave.
 


--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread djidjadji

If two requests want to create an M() they will get the same ID.
You must use some kind of transaction to get unique IDs

2009/4/18 风笑雪 kea...@gmail.com:
 I use this code to keep an id:
 class M(db.Model):
   id = db.IntegerProperty()
   time = db.DateTimeProperty(auto_now_add=True)
@staticmethod
def max_id():
 maxID = memcache.get('MaxID')
 if maxID:
   return maxID
 messages = Message.all()
 messages.order(-id)
 message = messages.get()
 if message:
   return message.id
 else:
   return 0
 entity = M()
 entity.id = M.maxID + 1
 entity.put()
 2009/4/19 David Wilson david.wil...@entertainmentcloud.com


 thanks! i missed that in the docs :)

 I wasnt using a datetime just to save a bit of space, but i can see i
 need to know to guarantee ordering, or if i want to do ordered paging
 via key i would need to handle key creation myself to make sure they
 are in order.

 This becomes harder in one case for me as users can create designs
 that need to be paged through in creation order. There will be too
 much contention on a glodal counter for this, so i guess an offset
 page on date is the best i can do for now. Or just not worry when some
 'new designs' are out of order.



 On Apr 18, 2:20 am, David Symonds dsymo...@gmail.com wrote:
  On Sat, Apr 18, 2009 at 3:21 PM, David Wilson
 
  david.wil...@entertainmentcloud.com wrote:
   Is this expected behaviour? and thus do i need to always give a
   key_name to guarantee order? this creates scaling issues for order
   counter (which is probably why its not in order in the backend :) )
 
  Keys are only guaranteed to be unique, not sequential or in order:
 
   http://code.google.com/appengine/docs/python/datastore/keysandentityg...
 
  What is wrong with giving your models a timestamp property (with
  auto_now_add=True), and sorting by that?
 
  Dave.



 


--~--~-~--~~~---~--~~
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: sort on _key_ out of order

2009-04-18 Thread 风笑雪
Well, but I don't care it, my application allows the same ID, I just need it
for sorting, and it's harder to sort by time when the browser do an AJAX
get. Some times I need handle the timezone difference between server
and browser.
If you want keep a unique ID, the best way is set its key_name, and try
again if put failed.

2009/4/19 djidjadji djidja...@gmail.com


 If two requests want to create an M() they will get the same ID.
 You must use some kind of transaction to get unique IDs

 2009/4/18 风笑雪 kea...@gmail.com:
  I use this code to keep an id:
  class M(db.Model):
id = db.IntegerProperty()
time = db.DateTimeProperty(auto_now_add=True)
 @staticmethod
 def max_id():
  maxID = memcache.get('MaxID')
  if maxID:
return maxID
  messages = Message.all()
  messages.order(-id)
  message = messages.get()
  if message:
return message.id
  else:
return 0
  entity = M()
  entity.id = M.maxID + 1
  entity.put()
  2009/4/19 David Wilson david.wil...@entertainmentcloud.com
 
 
  thanks! i missed that in the docs :)
 
  I wasnt using a datetime just to save a bit of space, but i can see i
  need to know to guarantee ordering, or if i want to do ordered paging
  via key i would need to handle key creation myself to make sure they
  are in order.
 
  This becomes harder in one case for me as users can create designs
  that need to be paged through in creation order. There will be too
  much contention on a glodal counter for this, so i guess an offset
  page on date is the best i can do for now. Or just not worry when some
  'new designs' are out of order.
 
 
 
  On Apr 18, 2:20 am, David Symonds dsymo...@gmail.com wrote:
   On Sat, Apr 18, 2009 at 3:21 PM, David Wilson
  
   david.wil...@entertainmentcloud.com wrote:
Is this expected behaviour? and thus do i need to always give a
key_name to guarantee order? this creates scaling issues for order
counter (which is probably why its not in order in the backend :) )
  
   Keys are only guaranteed to be unique, not sequential or in order:
  
  
 http://code.google.com/appengine/docs/python/datastore/keysandentityg...
  
   What is wrong with giving your models a timestamp property (with
   auto_now_add=True), and sorting by that?
  
   Dave.
 
 
 
  
 

 


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