Hi johntray, On Sun, Jun 21, 2009 at 5:47 PM, johntray <john.tur...@gmail.com> wrote:
> > Well yes I could add a count property to the B objects, but I'm really > trying to understand more about how ReferenceProperty works. ReferenceProperty's collection attributes are just syntactic sugar for creating and executing a query yourself. As such, all the same limitations apply. In the case where you call len() on it, I believe this will result in a count query being executed, which doesn't require Python to decode all the entities, but does require the datastore to fetch all the index rows. > > Nonetheless, there are a couple reasons I don't want to add a count > property to the B objects: > > -- Every time I create or delete an A object, I would also have to > make two additional datastore calls to read, modify, and write object > B. > > -- And to make sure the counter stays in sync, I would need to use a > datastore transaction for these operations. But right now, my A and B > objects are not in the same entity group, which means (if I understand > correctly) transactions are not supported. So I would have to do a > full update to the existing datastore in order to add a reliable > counter to object B. If you want to be able to count objects without O(n) work, your only option is to store a precalculated count of them. -Nick Johnson > > > > > On Jun 21, 12:31 pm, Sylvain <sylvain.viv...@gmail.com> wrote: > > Could you add an int property that is updated with the len ? > > So you only check this property ? > > > > On 21 juin, 17:51, johntray <john.tur...@gmail.com> wrote: > > > > > > > > > If I have two datastore object types, I'll call A and B, and A > > > includes a ReferenceProperty to B, then objects of type B will have a > > > back-reference property with default name a_set. Now if I just want > > > the size of some B object's a_set, I could call len(a_set). To execute > > > this, my understanding is that GAE will do a datastore query to > > > retrieve the relevant A objects and pass them to the len() function. > > > Since I don't need the A object contents, would it be more efficient > > > to set up my own Query object and call Query.count() instead? > > > -- Nick Johnson, App Engine Developer Programs Engineer Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---