How many database queries is my django rest api is calling?
- Run your django project locally in debug ( in visual studio)
- Place debug breakpoints at the points of the returns in the functions that would be called when you hit the api.
- Hit the api with appropriate payload.
- Run the following in the debug terminal of VS Code.
from django.db import connection
connection.querieslen(connection.queries)
- Above steps will give the database queries.
There is another way of capturing this information.
We can do this by creating a middleware. The middleware would log this information in a file. This will be a topic for another post.