优化看板打开速度

This commit is contained in:
GoEdgeLab
2022-03-27 16:39:54 +08:00
parent f5a58cbbbd
commit c0bd07409b
8 changed files with 120 additions and 82 deletions

View File

@@ -4,37 +4,39 @@ import "github.com/iwind/TeaGo/dbs"
// MetricItem 指标定义
type MetricItem struct {
Id uint64 `field:"id"` // ID
IsOn bool `field:"isOn"` // 是否启用
Code string `field:"code"` // 代号(用来区分是否内置)
Category string `field:"category"` // 类型比如http, tcp等
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 指标名称
Keys dbs.JSON `field:"keys"` // 统计的Key
Period uint32 `field:"period"` // 周期
PeriodUnit string `field:"periodUnit"` // 周期单位
Value string `field:"value"` // 值运算
State uint8 `field:"state"` // 状态
Version uint32 `field:"version"` // 版本号
IsPublic bool `field:"isPublic"` // 是否为公用
Id uint64 `field:"id"` // ID
IsOn bool `field:"isOn"` // 是否启用
Code string `field:"code"` // 代号(用来区分是否内置)
Category string `field:"category"` // 类型比如http, tcp等
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 指标名称
Keys dbs.JSON `field:"keys"` // 统计的Key
Period uint32 `field:"period"` // 周期
PeriodUnit string `field:"periodUnit"` // 周期单位
ExpiresPeriod uint32 `field:"expiresPeriod"` // 过期周期
Value string `field:"value"` // 值运算
State uint8 `field:"state"` // 状态
Version uint32 `field:"version"` // 版本号
IsPublic bool `field:"isPublic"` // 是否为公用
}
type MetricItemOperator struct {
Id interface{} // ID
IsOn interface{} // 是否启用
Code interface{} // 代号(用来区分是否内置)
Category interface{} // 类型比如http, tcp等
AdminId interface{} // 管理员ID
UserId interface{} // 用户ID
Name interface{} // 指标名称
Keys interface{} // 统计的Key
Period interface{} // 周期
PeriodUnit interface{} // 周期单位
Value interface{} // 值运算
State interface{} // 状态
Version interface{} // 版本号
IsPublic interface{} // 是否为公用
Id interface{} // ID
IsOn interface{} // 是否启用
Code interface{} // 代号(用来区分是否内置)
Category interface{} // 类型比如http, tcp等
AdminId interface{} // 管理员ID
UserId interface{} // 用户ID
Name interface{} // 指标名称
Keys interface{} // 统计的Key
Period interface{} // 周期
PeriodUnit interface{} // 周期单位
ExpiresPeriod interface{} // 过期周期
Value interface{} // 值运算
State interface{} // 状态
Version interface{} // 版本号
IsPublic interface{} // 是否为公用
}
func NewMetricItemOperator() *MetricItemOperator {

View File

@@ -1,16 +1,20 @@
package models
package models_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
_ "github.com/go-sql-driver/mysql"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"testing"
"time"
)
func TestNodeValueDAO_CreateValue(t *testing.T) {
var dao = NewNodeValueDAO()
var dao = models.NewNodeValueDAO()
m := maps.Map{
"hello": "world12344",
}
@@ -22,10 +26,29 @@ func TestNodeValueDAO_CreateValue(t *testing.T) {
}
func TestNodeValueDAO_Clean(t *testing.T) {
var dao = NewNodeValueDAO()
var dao = models.NewNodeValueDAO()
err := dao.Clean(nil)
if err != nil {
t.Fatal(err)
}
t.Log("ok")
}
func TestNodeValueDAO_CreateManyValues(t *testing.T) {
var dao = models.NewNodeValueDAO()
var tx *dbs.Tx
for i := 0; i < 1; i++ {
if i%10000 == 0 {
t.Log(i)
}
var item = "connections" + types.String(i)
var clusterId int64 = 42
var nodeId = rands.Int(1, 100)
err := dao.CreateValue(tx, clusterId, nodeconfigs.NodeRoleNode, int64(nodeId), item, []byte(`{"total":1}`), time.Now().Unix())
if err != nil {
t.Fatal("item: " + item + ", err: " + err.Error())
}
}
t.Log("finished")
}

View File

@@ -334,7 +334,7 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithServerId(tx *dbs.Tx
Table(table).
Attr("serverId", serverId).
Between("hour", hourFrom, hourTo).
UseIndex("hour").
UseIndex("serverId", "hour").
Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes").
Group("domain").
Desc("countRequests").

View File

@@ -33,12 +33,13 @@ func TestServerDomainHourlyStatDAO_FindAllPartitionTables(t *testing.T) {
t.Log(dao.FindAllPartitionTables())
}
func TestServerDomainHourlyStatDAO_IncreaseHourlyStat(t *testing.T) {
func TestServerDomainHourlyStatDAO_InsertManyHourlyStat(t *testing.T) {
dbs.NotifyReady()
for i := 0; i < 1_000_000; i++ {
var count = 1
for i := 0; i < count; i++ {
var f = string([]rune{int32(rands.Int('0', '9'))})
if i % 30 > 0 {
if i%30 > 0 {
f = string([]rune{int32(rands.Int('a', 'z'))})
}