mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
优化代码
This commit is contained in:
@@ -661,12 +661,11 @@ func (this *FileListDB) shouldRecover() bool {
|
||||
}
|
||||
var errString = ""
|
||||
var shouldRecover = false
|
||||
for result.Next() {
|
||||
if result.Next() {
|
||||
err = result.Scan(&errString)
|
||||
if strings.TrimSpace(errString) != "ok" {
|
||||
shouldRecover = true
|
||||
}
|
||||
break
|
||||
}
|
||||
_ = result.Close()
|
||||
return shouldRecover
|
||||
|
||||
@@ -47,6 +47,10 @@ func TestFileListDB_IncreaseHitAsync(t *testing.T) {
|
||||
}
|
||||
|
||||
err = db.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = db.IncreaseHitAsync("4598e5231ba47d6ec7aa9ea640ff2eaf")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -69,6 +73,9 @@ func TestFileListDB_CleanMatchKey(t *testing.T) {
|
||||
}
|
||||
|
||||
err = db.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = db.CleanMatchKey("https://*.goedge.cn/large-text")
|
||||
if err != nil {
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestParseHost(t *testing.T) {
|
||||
func TestUintString(t *testing.T) {
|
||||
t.Log(strconv.FormatUint(xxhash.Sum64String("https://goedge.cn/"), 10))
|
||||
t.Log(strconv.FormatUint(123456789, 10))
|
||||
t.Log(fmt.Sprintf("%d", 1234567890123))
|
||||
t.Logf("%d", 1234567890123)
|
||||
}
|
||||
|
||||
func BenchmarkUint_String(b *testing.B) {
|
||||
|
||||
@@ -122,6 +122,7 @@ func TestHTTPAccessLogQueue_Memory(t *testing.T) {
|
||||
}
|
||||
|
||||
runtime.GC()
|
||||
_ = accessLogs
|
||||
|
||||
// will not release automatically
|
||||
func() {
|
||||
@@ -131,6 +132,7 @@ func TestHTTPAccessLogQueue_Memory(t *testing.T) {
|
||||
RequestPath: "https://goedge.cn/hello/world",
|
||||
})
|
||||
}
|
||||
_ = accessLogs1
|
||||
}()
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
@@ -111,7 +111,7 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) {
|
||||
|
||||
// 处理SCRIPT_FILENAME
|
||||
scriptPath := env.GetString("SCRIPT_FILENAME")
|
||||
if len(scriptPath) > 0 && (strings.Index(scriptPath, "/") < 0 && strings.Index(scriptPath, "\\") < 0) {
|
||||
if len(scriptPath) > 0 && !strings.Contains(scriptPath, "/") && !strings.Contains(scriptPath, "\\") {
|
||||
env["SCRIPT_FILENAME"] = env.GetString("DOCUMENT_ROOT") + Tea.DS + scriptPath
|
||||
}
|
||||
scriptFilename := filepath.Base(this.RawReq.URL.Path)
|
||||
|
||||
@@ -210,7 +210,7 @@ func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http.
|
||||
// 检查host是否为IP
|
||||
func (this *HTTPListener) isIP(host string) bool {
|
||||
// IPv6
|
||||
if strings.Index(host, "[") > -1 {
|
||||
if strings.Contains(host, "[") {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ func BenchmarkBandwidthStatManager_Slice(b *testing.B) {
|
||||
NodeRegionId: 1,
|
||||
})
|
||||
}
|
||||
_ = pbStats
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +81,7 @@ func BenchmarkBandwidthStatManager_Slice2(b *testing.B) {
|
||||
var stat = &stats.BandwidthStat{}
|
||||
statsSlice = append(statsSlice, stat)
|
||||
}
|
||||
_ = statsSlice
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ func TestList_Map_Performance(t *testing.T) {
|
||||
for i := 0; i < 100_000; i++ {
|
||||
delete(m, uint64(i))
|
||||
}
|
||||
t.Log(time.Now().Sub(now))
|
||||
t.Log(time.Since(now))
|
||||
}
|
||||
|
||||
{
|
||||
@@ -166,7 +166,7 @@ func TestList_Map_Performance(t *testing.T) {
|
||||
for i := 0; i < 100_000; i++ {
|
||||
delete(m, uint32(i))
|
||||
}
|
||||
t.Log(time.Now().Sub(now))
|
||||
t.Log(time.Since(now))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,6 @@ func TestMapToObject(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if obj == nil {
|
||||
t.Fatal("obj should not be nil")
|
||||
}
|
||||
a.IsTrue(obj.B == 1024)
|
||||
a.IsTrue(obj.C == true)
|
||||
PrintT(obj, t)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 服务管理器
|
||||
// ServiceManager 服务管理器
|
||||
type ServiceManager struct {
|
||||
Name string
|
||||
Description string
|
||||
@@ -39,7 +39,7 @@ func (this *ServiceManager) setup() {
|
||||
this.onceLocker.Do(func() {
|
||||
logFile := files.NewFile(Tea.Root + "/logs/service.log")
|
||||
if logFile.Exists() {
|
||||
logFile.Delete()
|
||||
_ = logFile.Delete()
|
||||
}
|
||||
|
||||
//logger
|
||||
@@ -53,7 +53,7 @@ func (this *ServiceManager) setup() {
|
||||
})
|
||||
}
|
||||
|
||||
// 记录普通日志
|
||||
// Log 记录普通日志
|
||||
func (this *ServiceManager) Log(msg string) {
|
||||
this.setup()
|
||||
if this.logger == nil {
|
||||
@@ -62,7 +62,7 @@ func (this *ServiceManager) Log(msg string) {
|
||||
this.logger.Println("[info]" + msg)
|
||||
}
|
||||
|
||||
// 记录错误日志
|
||||
// LogError 记录错误日志
|
||||
func (this *ServiceManager) LogError(msg string) {
|
||||
this.setup()
|
||||
if this.logger == nil {
|
||||
@@ -71,7 +71,7 @@ func (this *ServiceManager) LogError(msg string) {
|
||||
this.logger.Println("[error]" + msg)
|
||||
}
|
||||
|
||||
// 关闭
|
||||
// Close 关闭
|
||||
func (this *ServiceManager) Close() error {
|
||||
if this.fp != nil {
|
||||
return this.fp.Close()
|
||||
@@ -100,7 +100,7 @@ func (this *ServiceManager) resetRoot() {
|
||||
Tea.SetTmpDir(Tea.Root + Tea.DS + "web" + Tea.DS + "tmp")
|
||||
}
|
||||
|
||||
// 保持命令行窗口是打开的
|
||||
// PauseWindow 保持命令行窗口是打开的
|
||||
func (this *ServiceManager) PauseWindow() {
|
||||
if runtime.GOOS != "windows" {
|
||||
return
|
||||
|
||||
@@ -133,7 +133,7 @@ func (this *CCCheckpoint) Options() []OptionInterface {
|
||||
option.Size = 8
|
||||
option.MaxLength = 8
|
||||
option.Validate = func(value string) (ok bool, message string) {
|
||||
if regexp.MustCompile("^\\d+$").MatchString(value) {
|
||||
if regexp.MustCompile(`^\d+$`).MatchString(value) {
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti
|
||||
period = 7 * 86400
|
||||
}
|
||||
|
||||
var threshold = options.GetInt64("threshold")
|
||||
/**var threshold = options.GetInt64("threshold")
|
||||
if threshold <= 0 {
|
||||
threshold = 1000
|
||||
}
|
||||
}**/
|
||||
|
||||
var ignoreCommonFiles = options.GetBool("ignoreCommonFiles")
|
||||
if ignoreCommonFiles {
|
||||
|
||||
Reference in New Issue
Block a user