#24190: "Don’t use len() on QuerySets" is too strong.
--------------------------------------+--------------------
Reporter: collinanderson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
I've seen people write code like:
{{{
qs = Model.objects.filter(a=b)
if qs.count() >= 1:
for q in qs:
# do something with q
}}}
They think the that ".count()" call is more efficient, but it actually
makes it slower. I asked the person about it they said: "the docs say
don't use len() on querysets".
--
Ticket URL: <https://code.djangoproject.com/ticket/24190>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.5b64b2988285d3f57749fa7a13e18a88%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.