mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
数据库某些表可以手工清理
This commit is contained in:
@@ -107,6 +107,10 @@ func (this *RPCClient) DBNodeRPC() pb.DBNodeServiceClient {
|
||||
return pb.NewDBNodeServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) DBRPC() pb.DBServiceClient {
|
||||
return pb.NewDBServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) OriginRPC() pb.OriginServiceClient {
|
||||
return pb.NewOriginServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package numberutils
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func FormatInt64(value int64) string {
|
||||
return strconv.FormatInt(value, 10)
|
||||
@@ -9,3 +12,17 @@ func FormatInt64(value int64) string {
|
||||
func FormatInt(value int) string {
|
||||
return strconv.Itoa(value)
|
||||
}
|
||||
|
||||
func FormatBytes(bytes int64) string {
|
||||
if bytes < 1024 {
|
||||
return FormatInt64(bytes) + "B"
|
||||
} else if bytes < 1024*1024 {
|
||||
return fmt.Sprintf("%.2fK", float64(bytes)/1024)
|
||||
} else if bytes < 1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2fM", float64(bytes)/1024/1024)
|
||||
} else if bytes < 1024*1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2fG", float64(bytes)/1024/1024/1024)
|
||||
} else {
|
||||
return fmt.Sprintf("%.2fP", float64(bytes)/1024/1024/1024/1024)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package profile
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
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
|
||||
@@ -13,3 +19,30 @@ func (this *CleanAction) Init() {
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteTableAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteTableAction) RunPost(params struct {
|
||||
Table string
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除数据表 %s", params.Table)
|
||||
|
||||
_, err := this.RPC().DBRPC().DeleteDBTable(this.AdminContext(), &pb.DeleteDBTableRequest{DbTable: params.Table})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -17,6 +17,8 @@ func init() {
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
GetPost("/clean", new(CleanAction)).
|
||||
GetPost("/cleanSetting", new(CleanSettingAction)).
|
||||
GetPost("/truncateTable", new(TruncateTableAction)).
|
||||
GetPost("/deleteTable", new(DeleteTableAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type TruncateTableAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TruncateTableAction) RunPost(params struct {
|
||||
Table string
|
||||
}) {
|
||||
defer this.CreateLogInfo("清空数据表 %s 数据", params.Table)
|
||||
|
||||
_, err := this.RPC().DBRPC().TruncateDBTable(this.AdminContext(), &pb.TruncateDBTableRequest{DbTable: params.Table})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,2 +1,24 @@
|
||||
{$layout}
|
||||
{$template "menu"}
|
||||
|
||||
<div class="ui message" v-if="isLoading">正在加载中...</div>
|
||||
|
||||
<table class="ui table selectable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>表名</th>
|
||||
<th>占用空间</th>
|
||||
<th>用途</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="table in tables">
|
||||
<td>{{table.name}}</td>
|
||||
<td>{{table.size}}</td>
|
||||
<td>{{table.comment}}</td>
|
||||
<td>
|
||||
<a href="" v-if="table.canDelete" @click.prevent="deleteTable(table.name)">删除</a><span v-if="table.canDelete"> </span>
|
||||
<a href="" v-if="table.canClean" @click.prevent="truncateTable(table.name)">清空</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
49
web/views/@default/settings/database/clean.js
Normal file
49
web/views/@default/settings/database/clean.js
Normal file
@@ -0,0 +1,49 @@
|
||||
Tea.context(function () {
|
||||
this.tables = []
|
||||
this.isLoading = true
|
||||
|
||||
this.$delay(function () {
|
||||
this.reload()
|
||||
})
|
||||
|
||||
this.reload = function () {
|
||||
this.isLoading = true
|
||||
this.$post("$")
|
||||
.success(function (resp) {
|
||||
this.tables = resp.data.tables;
|
||||
})
|
||||
.done(function () {
|
||||
this.isLoading = false
|
||||
})
|
||||
}
|
||||
|
||||
this.deleteTable = function (tableName) {
|
||||
let that = this
|
||||
teaweb.confirm("html:确定要删除此数据表吗?<br/>删除后数据不能恢复!", function () {
|
||||
that.$post(".deleteTable")
|
||||
.params({
|
||||
table: tableName
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("操作成功", function () {
|
||||
that.reload()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
this.truncateTable = function (tableName) {
|
||||
let that = this
|
||||
teaweb.confirm("html:确定要清空此数据表吗?<br/>清空后数据不能恢复!", function () {
|
||||
that.$post(".truncateTable")
|
||||
.params({
|
||||
table: tableName
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("操作成功", function () {
|
||||
that.reload()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user