mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 02:59:54 +03:00
This commit adds a new `slow_query_logger` function in `core/utils.py` that wraps Django database executions and logs queries taking longer than 100ms. It uses `time.monotonic()` for robust timing. The logger is globally registered in `core/apps.py` via the `connection_created` signal with `weak=False` to ensure all new database connections are properly instrumented. Unit tests have been added to `core/tests/test_slow_query.py` and the development plan checkbox is updated. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
18 lines
631 B
Python
18 lines
631 B
Python
from django.apps import AppConfig
|
|
|
|
|
|
class CoreConfig(AppConfig):
|
|
name = "core"
|
|
|
|
def ready(self):
|
|
from django.db.backends.signals import connection_created
|
|
from .utils import slow_query_logger
|
|
|
|
def register_slow_query_logger(sender, connection, **kwargs):
|
|
if slow_query_logger not in connection.execute_wrappers:
|
|
connection.execute_wrappers.append(slow_query_logger)
|
|
|
|
# Must retain the reference, otherwise the weakref used by connect() is garbage collected
|
|
# or we set weak=False
|
|
connection_created.connect(register_slow_query_logger, weak=False)
|