Skip to content

Commit

Permalink
Optimize slow-query list (#835)
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <crazycs520@gmail.com>
  • Loading branch information
crazycs520 authored and breezewish committed Jan 4, 2021
1 parent 583533e commit f0241c3
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions pkg/apiserver/slowquery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f0241c3

Please sign in to comment.