- Incorrect usage of the Django ORM is a common cause of performance issues. Therefore, it is important to know when querysets are evaluated (i.e., hit the database)
- Common mistakes that cause the queryset to be evaulated include iterating over the queryset or calling any of
len()
,list()
,bool()
with the queryset as an argument. - Reference: (QuerySet API reference | Django documentation | Django)
- Common mistakes that cause the queryset to be evaulated include iterating over the queryset or calling any of
- Use
exists()
to check if a queryset has any results in it.- Good:
queryset = Account.objects.filter(some_attribute=True)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
♥ git checkout -b experimental-theories | |
Switched to a new branch 'experimental-theories' |