From 7ca420ebdca9e8e6a2474df11bf8a93e94a31243 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 4 Apr 2024 13:33:32 +1100 Subject: [PATCH] Add support for django-query-count (#6948) * Add support for django-query-count * Display duplicate queries * Add comment in settings.py --- src/backend/InvenTree/InvenTree/settings.py | 20 ++++++++++++++++++++ src/backend/requirements-dev.in | 1 + src/backend/requirements-dev.txt | 1 + 3 files changed, 22 insertions(+) diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index de32aae38c..516096a6b4 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -268,6 +268,26 @@ MIDDLEWARE = CONFIG.get( ], ) +# In DEBUG mode, add support for django-querycount +# Ref: https://github.com/bradmontgomery/django-querycount +if DEBUG and get_boolean_setting( + 'INVENTREE_DEBUG_QUERYCOUNT', 'debug_querycount', False +): + MIDDLEWARE.append('querycount.middleware.QueryCountMiddleware') + +QUERYCOUNT = { + 'THRESHOLDS': { + 'MEDIUM': 50, + 'HIGH': 200, + 'MIN_TIME_TO_LOG': 0, + 'MIN_QUERY_COUNT_TO_LOG': 0, + }, + 'IGNORE_REQUEST_PATTERNS': ['^(?!\/(api)?(plugin)?\/).*'], + 'IGNORE_SQL_PATTERNS': [], + 'DISPLAY_DUPLICATES': 3, + 'RESPONSE_HEADER': 'X-Django-Query-Count', +} + AUTHENTICATION_BACKENDS = CONFIG.get( 'authentication_backends', [ diff --git a/src/backend/requirements-dev.in b/src/backend/requirements-dev.in index d27042e739..ab3c583153 100644 --- a/src/backend/requirements-dev.in +++ b/src/backend/requirements-dev.in @@ -2,6 +2,7 @@ -c requirements.txt coverage[toml] # Unit test coverage coveralls==2.1.2 # Coveralls linking (for tracking coverage) # PINNED 2022-06-28 - Old version needed for correct upload +django-querycount # Display number of URL queries for requests django-slowtests # Show which unit tests are running slowly django-test-migrations # Unit testing for database migrations isort # python import sorting diff --git a/src/backend/requirements-dev.txt b/src/backend/requirements-dev.txt index 845ccd2ca6..2f3df9693a 100644 --- a/src/backend/requirements-dev.txt +++ b/src/backend/requirements-dev.txt @@ -25,6 +25,7 @@ distlib==0.3.8 # via virtualenv django==4.2.11 # via django-slowtests +django-querycount==0.8.3 django-slowtests==1.1.1 django-test-migrations==1.3.0 docopt==0.6.2