数据库手动清理页面增加按表名和按占用空间排序/优化数据库相关界面

This commit is contained in:
GoEdgeLab
2023-04-26 09:49:28 +08:00
parent 7022410900
commit a513970930
5 changed files with 57 additions and 14 deletions

View File

@@ -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
}