> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codeant.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Performance

<AccordionGroup>
  <Accordion title="use-count-method">
    Looks like you need to determine the number of records. Django provides the count() method which is more efficient than .len(). See [https://docs.djangoproject.com/en/3.0/ref/models/querysets/](https://docs.djangoproject.com/en/3.0/ref/models/querysets/)
  </Accordion>

  <Accordion title="use-earliest-or-latest">
    Looks like you are only accessing first element of an ordered QuerySet. Use `latest()` or `earliest()` instead. See [https://docs.djangoproject.com/en/3.0/ref/models/querysets/#django.db.models.query.QuerySet.latest](https://docs.djangoproject.com/en/3.0/ref/models/querysets/#django.db.models.query.QuerySet.latest)
  </Accordion>

  <Accordion title="access-foreign-keys">
    You should use ITEM.user\_id rather than ITEM.user.id to prevent running an extra query.
  </Accordion>
</AccordionGroup>
