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

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
}

View File

@@ -1,9 +1,10 @@
<first-menu>
<menu-item href="/settings/database" code="index">详情</menu-item>
<menu-item href="/settings/database/update" code="update">修改</menu-item>
<menu-item href="/settings/database" code="index">配置模板</menu-item>
<menu-item href="/settings/database/update" code="update">修改模板</menu-item>
<span class="item disabled">|</span>
<menu-item href="/settings/database/clean" code="clean">手动清理</menu-item>
<menu-item href="/settings/database/cleanSetting" code="cleanSetting">自动清理设置</menu-item>
<span class="item">|</span>
<span class="item disabled">|</span>
<span class="item"><tip-icon content="在这里可以设置API节点可以使用的数据库修改后请重新配置并启动API节点才能生效。"></tip-icon></span>
</first-menu>
<div class="margin"></div>

View File

@@ -3,11 +3,15 @@
<div class="ui message" v-if="isLoading">正在加载中...</div>
<table class="ui table selectable">
<div class="ui message small warning" v-if="tables.length > 0">
<p>请确认数据表用途后再执行相关操作。</p>
</div>
<table class="ui table selectable" v-if="tables.length > 0">
<thead>
<tr>
<th>表名</th>
<th>占用空间</th>
<th>数据表名<sort-arrow name="orderTable"></sort-arrow></th>
<th>占用空间<sort-arrow name="orderSize"></sort-arrow></th>
<th>用途</th>
<th class="two op">操作</th>
</tr>

View File

@@ -9,6 +9,10 @@ Tea.context(function () {
this.reload = function () {
this.isLoading = true
this.$post("$")
.params({
orderTable: this.orderTable,
orderSize: this.orderSize
})
.success(function (resp) {
this.tables = resp.data.tables;
})

View File

@@ -1,6 +1,10 @@
{$layout}
{$template "menu"}
<div class="ui message small warning">
<p>这里只能修改配置模板文件里的配置信息,并不能直接修改数据库的用户名、密码等信息。</p>
</div>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table selectable definition">
<tr>
@@ -38,7 +42,3 @@
</table>
<submit-btn></submit-btn>
</form>
<div class="ui message small warning">
<p>修改数据库配置后需要重新配置API节点。</p>
</div>