优化集群列表性能

This commit is contained in:
GoEdgeLab
2023-06-23 16:15:22 +08:00
parent 7f392c1cc4
commit e5f5ba2a33
4 changed files with 68 additions and 2 deletions

2
go.mod
View File

@@ -13,7 +13,7 @@ require (
github.com/go-acme/lego/v4 v4.10.2 github.com/go-acme/lego/v4 v4.10.2
github.com/go-sql-driver/mysql v1.7.0 github.com/go-sql-driver/mysql v1.7.0
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/iwind/TeaGo v0.0.0-20230304012706-c1f4a4e27470 github.com/iwind/TeaGo v0.0.0-20230623080147-cd1e53b4915f
github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62 github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62
github.com/miekg/dns v1.1.50 github.com/miekg/dns v1.1.50
github.com/mozillazg/go-pinyin v0.18.0 github.com/mozillazg/go-pinyin v0.18.0

2
go.sum
View File

@@ -83,6 +83,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc= github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
github.com/iwind/TeaGo v0.0.0-20230304012706-c1f4a4e27470 h1:TuRxvKRv9PxKVijWOkUnZm5TeanQqWGUJyPx9u6cra4= github.com/iwind/TeaGo v0.0.0-20230304012706-c1f4a4e27470 h1:TuRxvKRv9PxKVijWOkUnZm5TeanQqWGUJyPx9u6cra4=
github.com/iwind/TeaGo v0.0.0-20230304012706-c1f4a4e27470/go.mod h1:fi/Pq+/5m2HZoseM+39dMF57ANXRt6w4PkGu3NXPc5s= github.com/iwind/TeaGo v0.0.0-20230304012706-c1f4a4e27470/go.mod h1:fi/Pq+/5m2HZoseM+39dMF57ANXRt6w4PkGu3NXPc5s=
github.com/iwind/TeaGo v0.0.0-20230623080147-cd1e53b4915f h1:xo6XmXLtveKcwcZAXV6VMxkWNzy/2dStfHEnyowsGAE=
github.com/iwind/TeaGo v0.0.0-20230623080147-cd1e53b4915f/go.mod h1:fi/Pq+/5m2HZoseM+39dMF57ANXRt6w4PkGu3NXPc5s=
github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62 h1:HJH6RDheAY156DnIfJSD/bEvqyXzsZuE2gzs8PuUjoo= github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62 h1:HJH6RDheAY156DnIfJSD/bEvqyXzsZuE2gzs8PuUjoo=
github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA= github.com/iwind/gosock v0.0.0-20220505115348-f88412125a62/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=

View File

@@ -262,19 +262,40 @@ func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string)
// ListEnabledClusters 列出单页集群 // ListEnabledClusters 列出单页集群
func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offset, size int64) (result []*NodeCluster, err error) { func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offset, size int64) (result []*NodeCluster, err error) {
query := this.Query(tx). var query = this.Query(tx).
State(NodeClusterStateEnabled) State(NodeClusterStateEnabled)
if len(keyword) > 0 { if len(keyword) > 0 {
query.Where("(name LIKE :keyword OR dnsName like :keyword OR (dnsDomainId > 0 AND dnsDomainId IN (SELECT id FROM "+dns.SharedDNSDomainDAO.Table+" WHERE name LIKE :keyword AND state=1)))"). query.Where("(name LIKE :keyword OR dnsName like :keyword OR (dnsDomainId > 0 AND dnsDomainId IN (SELECT id FROM "+dns.SharedDNSDomainDAO.Table+" WHERE name LIKE :keyword AND state=1)))").
Param("keyword", dbutils.QuoteLike(keyword)) Param("keyword", dbutils.QuoteLike(keyword))
} }
_, err = query. _, err = query.
Result(
NodeClusterFieldId,
NodeClusterFieldName,
NodeClusterFieldIsOn,
NodeClusterFieldIsPinned,
NodeClusterFieldInstallDir,
NodeClusterFieldHttpFirewallPolicyId,
NodeClusterFieldAdminId,
NodeClusterFieldIsOn,
NodeClusterFieldIsAD,
NodeClusterFieldUserId,
NodeClusterFieldDnsName,
NodeClusterFieldDnsDomainId,
NodeClusterFieldDns,
NodeClusterFieldCreatedAt,
NodeClusterFieldUniqueId,
NodeClusterFieldSecret,
NodeClusterFieldGrantId,
NodeClusterFieldTimeZone,
).
Offset(offset). Offset(offset).
Limit(size). Limit(size).
Slice(&result). Slice(&result).
Desc("isPinned"). Desc("isPinned").
DescPk(). DescPk().
FindAll() FindAll()
return return
} }

View File

@@ -2,6 +2,49 @@ package models
import "github.com/iwind/TeaGo/dbs" import "github.com/iwind/TeaGo/dbs"
const (
NodeClusterFieldId dbs.FieldName = "id" // ID
NodeClusterFieldAdminId dbs.FieldName = "adminId" // 管理员ID
NodeClusterFieldUserId dbs.FieldName = "userId" // 用户ID
NodeClusterFieldIsOn dbs.FieldName = "isOn" // 是否启用
NodeClusterFieldName dbs.FieldName = "name" // 名称
NodeClusterFieldUseAllAPINodes dbs.FieldName = "useAllAPINodes" // 是否使用所有API节点
NodeClusterFieldApiNodes dbs.FieldName = "apiNodes" // 使用的API节点
NodeClusterFieldInstallDir dbs.FieldName = "installDir" // 安装目录
NodeClusterFieldOrder dbs.FieldName = "order" // 排序
NodeClusterFieldCreatedAt dbs.FieldName = "createdAt" // 创建时间
NodeClusterFieldGrantId dbs.FieldName = "grantId" // 默认认证方式
NodeClusterFieldSshParams dbs.FieldName = "sshParams" // SSH默认参数
NodeClusterFieldState dbs.FieldName = "state" // 状态
NodeClusterFieldAutoRegister dbs.FieldName = "autoRegister" // 是否开启自动注册
NodeClusterFieldUniqueId dbs.FieldName = "uniqueId" // 唯一ID
NodeClusterFieldSecret dbs.FieldName = "secret" // 密钥
NodeClusterFieldHealthCheck dbs.FieldName = "healthCheck" // 健康检查
NodeClusterFieldDnsName dbs.FieldName = "dnsName" // DNS名称
NodeClusterFieldDnsDomainId dbs.FieldName = "dnsDomainId" // 域名ID
NodeClusterFieldDns dbs.FieldName = "dns" // DNS配置
NodeClusterFieldToa dbs.FieldName = "toa" // TOA配置
NodeClusterFieldCachePolicyId dbs.FieldName = "cachePolicyId" // 缓存策略ID
NodeClusterFieldHttpFirewallPolicyId dbs.FieldName = "httpFirewallPolicyId" // WAF策略ID
NodeClusterFieldAccessLog dbs.FieldName = "accessLog" // 访问日志设置
NodeClusterFieldSystemServices dbs.FieldName = "systemServices" // 系统服务设置
NodeClusterFieldTimeZone dbs.FieldName = "timeZone" // 时区
NodeClusterFieldNodeMaxThreads dbs.FieldName = "nodeMaxThreads" // 节点最大线程数
NodeClusterFieldDdosProtection dbs.FieldName = "ddosProtection" // DDoS防护设置
NodeClusterFieldAutoOpenPorts dbs.FieldName = "autoOpenPorts" // 是否自动尝试开放端口
NodeClusterFieldIsPinned dbs.FieldName = "isPinned" // 是否置顶
NodeClusterFieldWebp dbs.FieldName = "webp" // WebP设置
NodeClusterFieldUam dbs.FieldName = "uam" // UAM设置
NodeClusterFieldClock dbs.FieldName = "clock" // 时钟配置
NodeClusterFieldGlobalServerConfig dbs.FieldName = "globalServerConfig" // 全局服务配置
NodeClusterFieldAutoRemoteStart dbs.FieldName = "autoRemoteStart" // 自动远程启动
NodeClusterFieldAutoInstallNftables dbs.FieldName = "autoInstallNftables" // 自动安装nftables
NodeClusterFieldIsAD dbs.FieldName = "isAD" // 是否为高防集群
NodeClusterFieldHttpPages dbs.FieldName = "httpPages" // 自定义页面设置
NodeClusterFieldCc dbs.FieldName = "cc" // CC设置
NodeClusterFieldHttp3 dbs.FieldName = "http3" // HTTP3设置
)
// NodeCluster 节点集群 // NodeCluster 节点集群
type NodeCluster struct { type NodeCluster struct {
Id uint32 `field:"id"` // ID Id uint32 `field:"id"` // ID