Coverage for django_query_capture/presenter/raw_line.py: 87%
15 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
1import sqlparse
3from django_query_capture.presenter.base import BasePresenter
4from django_query_capture.utils import get_stack_prefix
7class RawLinePresenter(BasePresenter):
8 """
9 Outputs all elements of [ClassifiedQuery][classify.ClassifiedQuery] without formatting.
10 """
12 def print(self) -> None:
13 print(
14 f"read: {self.classified_query['read']}\n",
15 f"writes: {self.classified_query['writes']}\n",
16 f"total: {self.classified_query['total']}\n",
17 f"total_duration: {self.classified_query['total_duration']:.2f}\n",
18 f"most_common_duplicates: {self.classified_query['most_common_duplicate'][1] if self.classified_query['most_common_duplicate'] else 0}\n",
19 f"most_common_similar: {self.classified_query['most_common_similar'][1] if self.classified_query['most_common_similar'] else 0}\n",
20 )
22 for captured_query in self.classified_query["slow_captured_queries"]:
23 print(
24 f'{get_stack_prefix(captured_query)} Slow {captured_query["duration"]:.2f} seconds'
25 )
26 print(
27 sqlparse.format(
28 captured_query["sql"], reindent=True, keyword_case="upper"
29 )
30 )
32 for captured_query, count in self.classified_query[
33 "duplicates_counter_over_threshold"
34 ].items():
35 print(f"{get_stack_prefix(captured_query)} Repeated {count} times")
36 print(
37 sqlparse.format(
38 captured_query["sql"], reindent=True, keyword_case="upper"
39 )
40 )
42 for captured_query, count in self.classified_query[
43 "similar_counter_over_threshold"
44 ].items():
45 print(f"{get_stack_prefix(captured_query)} Similar {count} times")
46 print(
47 sqlparse.format(
48 captured_query["sql"], reindent=True, keyword_case="upper"
49 )
50 )