mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
修复当数据库设置为lower_case_table_names=1时无法查询访问日志的Bug
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
@@ -141,7 +142,7 @@ func findNSAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool
|
||||
return tableName, false, err
|
||||
}
|
||||
|
||||
return tableName, lists.ContainsString(tableNames, tableName), nil
|
||||
return tableName, utils.ContainsStringInsensitive(tableNames, tableName), nil
|
||||
}
|
||||
|
||||
// 根据日期获取表名
|
||||
@@ -168,7 +169,7 @@ func findHTTPAccessLogTable(db *dbs.DB, day string, force bool) (*httpAccessLogD
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if lists.ContainsString(tableNames, tableName) {
|
||||
if utils.ContainsStringInsensitive(tableNames, tableName) {
|
||||
table, err := db.FindTable(tableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -236,7 +237,7 @@ func findNSAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
||||
return tableName, err
|
||||
}
|
||||
|
||||
if lists.ContainsString(tableNames, tableName) {
|
||||
if utils.ContainsStringInsensitive(tableNames, tableName) {
|
||||
accessLogLocker.Lock()
|
||||
nsAccessLogTableMapping[cacheKey] = true
|
||||
accessLogLocker.Unlock()
|
||||
@@ -364,6 +365,7 @@ func (this *DBNodeInitializer) loop() error {
|
||||
continue
|
||||
} else {
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,14 +306,14 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
||||
dao := daoWrapper.DAO
|
||||
|
||||
tableName, hasRemoteAddrField, hasDomainField, exists, err := findHTTPAccessLogTableName(dao.Instance, day)
|
||||
if !exists {
|
||||
// 表格不存在则跳过
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
logs.Println("[DB_NODE]" + err.Error())
|
||||
return
|
||||
}
|
||||
if !exists {
|
||||
// 表格不存在则跳过
|
||||
return
|
||||
}
|
||||
|
||||
query := dao.Query(tx)
|
||||
|
||||
|
||||
@@ -19,3 +19,14 @@ func SplitStrings(s string, glue string) []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ContainsStringInsensitive 检查是否包含某个字符串,并且不区分大小写
|
||||
func ContainsStringInsensitive(list []string, search string) bool {
|
||||
search = strings.ToLower(search)
|
||||
for _, s := range list {
|
||||
if strings.ToLower(s) == search {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -2,9 +2,21 @@
|
||||
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSplitStrings(t *testing.T) {
|
||||
t.Log(SplitStrings("a, b, c", ","))
|
||||
t.Log(SplitStrings("a, b, c, ", ","))
|
||||
}
|
||||
|
||||
func TestContainsStringInsensitive(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
a.IsTrue(ContainsStringInsensitive([]string{"a", "b", "C"}, "A"))
|
||||
a.IsTrue(ContainsStringInsensitive([]string{"a", "b", "C"}, "b"))
|
||||
a.IsTrue(ContainsStringInsensitive([]string{"a", "b", "C"}, "c"))
|
||||
a.IsFalse(ContainsStringInsensitive([]string{"a", "b", "C"}, "d"))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user