Forge Pro

forge-querystats

On each page, the query stats will display how many database queries were performed and how long they took.

Clicking the stats in the toolbar will show the full SQL query log with tracebacks and timings. This is even designed to work in production, making it much easier to discover and debug performance issues on production data!

Django query stats

It will also point out duplicate queries, which can typically be removed by using select_related, prefetch_related, or otherwise refactoring your code.

Installation

# settings.py
INSTALLED_APPS = [
    # ...
    "forgequerystats",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",

    "forgequerystats.QueryStatsMiddleware",
    # Put additional middleware below querystats
    # ...
]

We strongly recommend using the forge-stafftoolbar along with this, but if you aren't, you can add the querystats to your frontend templates with this include:

{% include "querystats/button.html" %}

Note that you will likely want to surround this with an if DEBUG or is_staff check.

To view querystats you need to send a POST request to ?querystats=store (i.e. via a <form>), and the template include is the easiest way to do that.

Tailwind CSS

This package is styled with Tailwind CSS, and pairs well with forge-tailwind.

If you are using your own Tailwind implementation, you can modify the "content" in your Tailwind config to include any Forge packages:

// tailwind.config.js
module.exports = {
  content: [
    // ...
    ".venv/lib/python*/site-packages/forge*/**/*.{html,js}",
  ],
  // ...
}

If you aren't using Tailwind, and don't intend to, open an issue to discuss other options.