-
Notifications
You must be signed in to change notification settings - Fork 4
/
clean.go
48 lines (42 loc) · 1.14 KB
/
clean.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package database
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type CleanAction struct {
actionutils.ParentAction
}
func (this *CleanAction) Init() {
this.Nav("", "", "clean")
}
func (this *CleanAction) RunGet(params struct{}) {
this.Show()
}
func (this *CleanAction) RunPost(params struct {
Must *actions.Must
}) {
tablesResp, err := this.RPC().DBRPC().FindAllDBTables(this.AdminContext(), &pb.FindAllDBTablesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
tableMaps := []maps.Map{}
for _, table := range tablesResp.DbTables {
if !table.IsBaseTable || (!table.CanClean && !table.CanDelete) {
continue
}
tableMaps = append(tableMaps, maps.Map{
"name": table.Name,
"rows": table.Rows,
"size": numberutils.FormatBytes(table.DataLength + table.IndexLength),
"canDelete": table.CanDelete,
"canClean": table.CanClean,
"comment": table.Comment,
})
}
this.Data["tables"] = tableMaps
this.Success()
}