Coverage for django_query_capture/settings.py: 100%
16 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-11-20 10:20 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-11-20 10:20 +0000
1"""
2This is the [default setting](../home/settings.md) of django_query_capture.
3You can adjust the threshold or change the shape of the output by referring to [settings](../home/settings.md).
4"""
5import typing
7from functools import lru_cache
9from django.conf import settings
10from django.core.signals import setting_changed
11from django.dispatch import receiver
13CONFIG_DEFAULTS = {
14 "PRINT_THRESHOLDS": {
15 "SLOW_MIN_SECOND": 1,
16 "DUPLICATE_MIN_COUNT": 10,
17 "SIMILAR_MIN_COUNT": 10,
18 "COLOR": "magenta",
19 },
20 "PRESENTER": "django_query_capture.presenter.PrettyPresenter",
21 "IGNORE_SQL_PATTERNS": [],
22 "PRETTY": {"TABLE_FORMAT": "pretty", "SQL_COLOR_FORMAT": "paraiso-light"},
23}
26@lru_cache
27def get_config() -> typing.Dict[str, typing.Any]:
28 """
29 Utilities that help you use the default settings if you don't use the user
30 Returns:
31 Among the values of [settings](../home/settings.md), the existing value is returned.
32 """
33 USER_CONFIG = getattr(settings, "QUERY_CAPTURE", {})
34 CONFIG = CONFIG_DEFAULTS.copy()
35 CONFIG.update(USER_CONFIG)
36 return CONFIG
39@receiver(setting_changed)
40def update_toolbar_config(*, setting, **kwargs):
41 """
42 Refresh configuration when overriding settings.
43 """
44 if setting == "QUERY_CAPTURE":
45 get_config.cache_clear()