From 585dc7e6535c5ba088f783c969f31f5d1e88c886 Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 4 Jan 2021 19:48:22 +0800 Subject: [PATCH] Optimize slow-query list (#835) Signed-off-by: crazycs520 --- pkg/apiserver/slowquery/queries.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/pkg/apiserver/slowquery/queries.go b/pkg/apiserver/slowquery/queries.go index 6b356cd4ed..9382f3e050 100644 --- a/pkg/apiserver/slowquery/queries.go +++ b/pkg/apiserver/slowquery/queries.go @@ -219,24 +219,10 @@ func QuerySlowLogList(db *gorm.DB, req *GetListRequest) ([]SlowQuery, error) { tx = tx.Where("DB IN (?)", req.DB) } - // more robust - if req.OrderBy == "" { - req.OrderBy = "timestamp" - } - - order, err := getProjectionsByFields(req.OrderBy) - if err != nil { - return nil, err - } - // to handle the special case: timestamp - // if req.OrderBy is "timestamp", then the order is "(unix_timestamp(Time) + 0E0) AS timestamp" - if strings.Contains(order[0], " AS ") { - order[0] = req.OrderBy - } if req.IsDesc { - tx = tx.Order(fmt.Sprintf("%s DESC", order[0])) + tx = tx.Order("Time DESC") } else { - tx = tx.Order(fmt.Sprintf("%s ASC", order[0])) + tx = tx.Order("Time ASC") } if len(req.Plans) > 0 {