On Thursday 26 January 2006 23:45, Joseph Kocherhans wrote:

> Let's assume that MyModel.objects or my_object.related_set *IS* a
> Query object (in other words, it has state):

It's state is simply an empty set of where clauses and an empty order by 
list and these never actually change.

> q = MyModel.objects # q is Q1
> q.filter(*args) # q is still Q1, but with filters now

No, q.filter(*args) is a *new* set, it doesn't change q 

> q.order_by('test') # q is still Q1 + filters + ordering

Again, a new set, which doesn't include the filter at all.  The clone 
would be done by the filter() and order_by() methods.

Unless I'm missing something about why that isn't possible?

> Ian Bicking has kept len() out of SQLObject result sets even though
> it seems really intuitive to use. Here's a rundown of what I remember
> about his argument: __len__ would run "count (*)" against the db. I
> think iter() calls len() implicitly for performance reasons, so you'd
> be running a useless count(*) every time you started iterating over a
> Query object. On the other hand, maybe if the iterator has already
> cahced the objects, __len__ could just call len() on the cache. It
> might be possible to work something out.

I'm happy with that, but I've done some quick tests and it doesn't seem 
that __len__ is called when you get or use the iterator.

The only issue I've come across is that since managers are used to do 
related object lookups, and related objects are cached, so are all 
queries done by the manager - so iterating over Article.objects will 
retrieve all the articles and keep them in a cache.  But I imagine some 
weakrefs will be adequate to sort that out.

Luke

-- 
I heard a man say that brigands demand your money or your life, whereas 
women require both. (Samuel Butler)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

-- 
"I imagine bugs and girls have a dim suspicion that nature played a 
cruel trick on them, but they lack the intelligence to really 
comprehend the magnitude of it." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

Attachment: pgp05cJwmSny5.pgp
Description: PGP signature

Reply via email to