mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 08:26:35 +08:00
优化代码
This commit is contained in:
@@ -662,7 +662,7 @@ func (this *FileListDB) shouldRecover() bool {
|
||||
var errString = ""
|
||||
var shouldRecover = false
|
||||
if result.Next() {
|
||||
err = result.Scan(&errString)
|
||||
_ = result.Scan(&errString)
|
||||
if strings.TrimSpace(errString) != "ok" {
|
||||
shouldRecover = true
|
||||
}
|
||||
|
||||
@@ -101,6 +101,9 @@ func TestFileListDB_CleanMatchPrefix(t *testing.T) {
|
||||
}
|
||||
|
||||
err = db.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = db.CleanMatchPrefix("https://*.goedge.cn/large-text")
|
||||
if err != nil {
|
||||
|
||||
@@ -148,8 +148,7 @@ func (this *Manager) FindPolicy(policyId int64) *serverconfigs.HTTPCachePolicy {
|
||||
this.locker.RLock()
|
||||
defer this.locker.RUnlock()
|
||||
|
||||
p, _ := this.policyMap[policyId]
|
||||
return p
|
||||
return this.policyMap[policyId]
|
||||
}
|
||||
|
||||
// FindStorageWithPolicy 根据策略ID查找存储
|
||||
@@ -157,8 +156,7 @@ func (this *Manager) FindStorageWithPolicy(policyId int64) StorageInterface {
|
||||
this.locker.RLock()
|
||||
defer this.locker.RUnlock()
|
||||
|
||||
storage, _ := this.storageMap[policyId]
|
||||
return storage
|
||||
return this.storageMap[policyId]
|
||||
}
|
||||
|
||||
// NewStorageWithPolicy 根据策略获取存储对象
|
||||
|
||||
@@ -1276,13 +1276,6 @@ func (this *FileStorage) increaseHit(key string, hash string, reader Reader) {
|
||||
this.hotMapLocker.Lock()
|
||||
hotItem, ok := this.hotMap[key]
|
||||
|
||||
// 限制热点数据存活时间
|
||||
var unixTime = time.Now().Unix()
|
||||
var expiresAt = reader.ExpiresAt()
|
||||
if expiresAt <= 0 || expiresAt > unixTime+HotItemLifeSeconds {
|
||||
expiresAt = unixTime + HotItemLifeSeconds
|
||||
}
|
||||
|
||||
if ok {
|
||||
hotItem.Hits++
|
||||
} else if len(this.hotMap) < HotItemSize { // 控制数量
|
||||
|
||||
@@ -8,7 +8,7 @@ import "strings"
|
||||
func partialRangesFilePath(path string) string {
|
||||
// ranges路径
|
||||
var dotIndex = strings.LastIndex(path, ".")
|
||||
var rangePath = ""
|
||||
var rangePath string
|
||||
if dotIndex < 0 {
|
||||
rangePath = path + "@ranges.cache"
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user