From 7637db3c93ffacfb506ff98c515124bf0f9cc202 Mon Sep 17 00:00:00 2001 From: Grain-Yu Date: Thu, 23 Nov 2023 14:46:18 +0800 Subject: [PATCH 01/10] =?UTF-8?q?draft:=20=E6=B7=BB=E5=8A=A0sql=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=AF=A6=E6=83=85=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 1 + sql/slowlog.py | 6 ++++-- sql/templates/slowquery.html | 36 ++++++++++++++++++++++++++++++++++++ sql/urls.py | 1 + sql/views.py | 4 ++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/sql/models.py b/sql/models.py index 16aaef6..815d60f 100644 --- a/sql/models.py +++ b/sql/models.py @@ -921,6 +921,7 @@ class SlowQuery(models.Model): reviewed_by = models.CharField(max_length=20, blank=True, null=True) reviewed_on = models.DateTimeField(blank=True, null=True) comments = models.TextField(blank=True, null=True) + reviewed_status = models.CharField(max_length=24, blank=True, null=True) class Meta: managed = False diff --git a/sql/slowlog.py b/sql/slowlog.py index 624520b..94bffbf 100644 --- a/sql/slowlog.py +++ b/sql/slowlog.py @@ -67,8 +67,8 @@ def slowquery_review(request): fingerprint__icontains=search, **filter_kwargs ) - .annotate(SQLText=F("fingerprint"), SQLId=F("checksum")) - .values("SQLText", "SQLId") + .annotate(SQLText=F("fingerprint"), SQLId=F("checksum"), ReviewedBy=F("reviedwd_by"), ReviewedOn=F("reviewed_on"), Comments=F("comments"), ReviewedStatus=F("reviewed_status")) + .values("SQLText", "SQLId", "ReviewedBy", "ReviewedOn", "Comments", "ReviewedStatus") .annotate( CreateTime=Max("slowqueryhistory__ts_max"), DBName=Max("slowqueryhistory__db_max"), # 数据库 @@ -157,6 +157,7 @@ def slowquery_review_history(request): sample__icontains=search, **filter_kwargs ).annotate( + SQLChecksum=F("checksum"), # SQL语句校验和 ExecutionStartTime=F("ts_min"), # 本次统计(每5分钟一次)该类型sql语句出现的最小时间 DBName=F("db_max"), # 数据库名 HostAddress=Concat( @@ -175,6 +176,7 @@ def slowquery_review_history(request): slow_sql_record_list = slow_sql_record_obj.order_by( "-" + sortName if "desc".__eq__(sortOrder) else sortName )[offset:limit].values( + "SQLChecksum", "ExecutionStartTime", "DBName", "HostAddress", diff --git a/sql/templates/slowquery.html b/sql/templates/slowquery.html index 0219c89..5d01e27 100644 --- a/sql/templates/slowquery.html +++ b/sql/templates/slowquery.html @@ -4,6 +4,7 @@