This repository contains the codebase for the article Find and Fix N+1 Queries in Django using AppSignal.
It is split into two branches:
base
-- serves as a starting point to follow the articlemaster
-- contains the final codebase after fixing the N+1 problems
-
Fork/Clone
-
Create and activate a virtual environment:
$ python3 -m venv venv && source venv/bin/activate
-
Install the requirements:
(venv)$ pip install -r requirements.txt
-
Apply the migrations:
(venv)$ python manage.py migrate
-
Populate the database:
(venv)$ python manage.py populate_db
-
Create a .env file with the following contents:
APPSIGNAL_PUSH_API_KEY=<your_push_api_key>
-
Run the server:
(venv)$ python manage.py runserver
-
Navigate to http://localhost:8000/ in your browser. N+1 problematic endpoints are:
books/
books/by-author
admin/books/author/1/change/
The superuser credentials after populating the database are:
user: admin
pass: password