Improve your Django website speed

Time

Over half of Django websites are being slowed down by inefficient code. This is a problem because customers leave slow websites.

Code Review Doctor checks that your code follows the Django documentation database best practices, and offers the fix to reduce developer effort.

This improves customer bounce rate by helping prevent your website from being slowed by inefficient code.

Try the Code Review Doctor database performance challenge to see the improvements Code Review Doctor suggests.

Code Review Doctor checks for the following database performance anti-patterns:

  • Using len(queryset) instead of queryset.count()

    performancemedium

    len(queryset) performs the count at application level. That is much less efficient than doing queryset.count(), which does the calculation at database level and just returns the count.

    Read more
  • Not using foreign keys directly

    performancemedium

    When working with foreign keys, accessing the related field will result in a database read. That can be eliminated by using *_id, which is the foreign key value that Django has already cached on the object to make this scenario more efficient.

    Read more
  • Comparing queryset.count() instead of checking queryset.exists()

    performancemedium

    Comparing queryset.count() is less efficient than checking queryset.exists(), so use querySet.count() if you only want the count, and use queryset.exists() if you only want to find out if at least one result exists.

    Read more
  • Checking queryset truthiness instead of checking queryset.exists()

    performancemedium

    This can load every row in the database table into memory because the queryset is evaluated. Checking if a queryset is truthy/falsey is much less efficient than checking queryset.exists().

    Read more
  • Random ordering via order_by("?")

    performancemedium

    Using order_by('?') can be very inefficient if you have lots of rows in the table. Moving the randomness to the application layer will probably give significant a performance improvement.

    Read more
  • Are you ready to improve your Django performance? Add Code Review Doctor to GitHub.