优化IP名单使用IP搜索查询速度

This commit is contained in:
刘祥超
2023-07-25 12:26:12 +08:00
parent 814b82e1b6
commit 9a3438e066

View File

@@ -14,6 +14,7 @@ import (
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"math" "math"
"net"
"time" "time"
) )
@@ -498,7 +499,11 @@ func (this *IPItemDAO) CountAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, ke
} }
} }
if len(keyword) > 0 { if len(keyword) > 0 {
query.Like("ipFrom", dbutils.QuoteLike(keyword)) if net.ParseIP(keyword) != nil { // 是一个IP地址
query.Attr("ipFrom", keyword)
} else {
query.Like("ipFrom", dbutils.QuoteLike(keyword))
}
} }
if len(ip) > 0 { if len(ip) > 0 {
query.Attr("ipFrom", ip) query.Attr("ipFrom", ip)
@@ -540,7 +545,11 @@ func (this *IPItemDAO) ListAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, key
} }
} }
if len(keyword) > 0 { if len(keyword) > 0 {
query.Like("ipFrom", dbutils.QuoteLike(keyword)) if net.ParseIP(keyword) != nil { // 是一个IP地址
query.Attr("ipFrom", keyword)
} else {
query.Like("ipFrom", dbutils.QuoteLike(keyword))
}
} }
if len(ip) > 0 { if len(ip) > 0 {
query.Attr("ipFrom", ip) query.Attr("ipFrom", ip)