mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
数据库手动清理页面增加按表名和按占用空间排序/优化数据库相关界面
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type CleanAction struct {
|
||||
@@ -16,11 +17,20 @@ func (this *CleanAction) Init() {
|
||||
this.Nav("", "", "clean")
|
||||
}
|
||||
|
||||
func (this *CleanAction) RunGet(params struct{}) {
|
||||
func (this *CleanAction) RunGet(params struct {
|
||||
OrderTable string
|
||||
OrderSize string
|
||||
}) {
|
||||
this.Data["orderTable"] = params.OrderTable
|
||||
this.Data["orderSize"] = params.OrderSize
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CleanAction) RunPost(params struct {
|
||||
OrderTable string
|
||||
OrderSize string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
tablesResp, err := this.RPC().DBRPC().FindAllDBTables(this.AdminContext(), &pb.FindAllDBTablesRequest{})
|
||||
@@ -28,9 +38,33 @@ func (this *CleanAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var tables = tablesResp.DbTables
|
||||
|
||||
tableMaps := []maps.Map{}
|
||||
for _, table := range tablesResp.DbTables {
|
||||
// 排序
|
||||
switch params.OrderTable {
|
||||
case "asc":
|
||||
sort.Slice(tables, func(i, j int) bool {
|
||||
return tables[i].Name < tables[j].Name
|
||||
})
|
||||
case "desc":
|
||||
sort.Slice(tables, func(i, j int) bool {
|
||||
return tables[i].Name > tables[j].Name
|
||||
})
|
||||
}
|
||||
|
||||
switch params.OrderSize {
|
||||
case "asc":
|
||||
sort.Slice(tables, func(i, j int) bool {
|
||||
return tables[i].DataLength+tables[i].IndexLength < tables[j].DataLength+tables[j].IndexLength
|
||||
})
|
||||
case "desc":
|
||||
sort.Slice(tables, func(i, j int) bool {
|
||||
return tables[i].DataLength+tables[i].IndexLength > tables[j].DataLength+tables[j].IndexLength
|
||||
})
|
||||
}
|
||||
|
||||
var tableMaps = []maps.Map{}
|
||||
for _, table := range tables {
|
||||
if !table.IsBaseTable || (!table.CanClean && !table.CanDelete) {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user