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