#4399: Add __nonzero__ to allow querysets to efficiently test for emptiness
------------------------------------------+---------------------------------
Reporter:  Michael Axiak <[EMAIL PROTECTED]>  |       Owner:  adrian            
                  
  Status:  new                            |   Component:  Database wrapper      
              
 Version:  SVN                            |    Keywords:  
database,performance,existence,patch
   Stage:  Unreviewed                     |   Has_patch:  1                     
              
------------------------------------------+---------------------------------
 Currently, if you do:
 {{{
 #!python
 if Model.objects.filter(Complicated):
    ...
 }}}
 you're asking for performance trouble, since it will issue a {{{__len__}}}
 statement on it. Most people will solve this problem by doing:
 {{{
 #!python
 if Model.objects.filter(Complicated).count() > 0:
    ...
 }}}
 
 But this is '''still''' much slower than doing a SELECT LIMIT 1. Thus, I
 propose adding a {{{__nonzero__}}} function, so that the first method of
 checking for emptiness does the right thing.
 (http://docs.python.org/ref/customization.html)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4399>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to