优化代码

This commit is contained in:
刘祥超
2022-11-29 15:33:12 +08:00
parent b2a1bef08f
commit bbcfdbbf5e
5 changed files with 8 additions and 15 deletions

View File

@@ -180,6 +180,9 @@ func (this *FileListDB) Init() error {
}
this.selectHashListStmt, err = this.readDB.Prepare(`SELECT "id", "hash" FROM "` + this.itemsTableName + `" WHERE id>:id ORDER BY id ASC LIMIT 2000`)
if err != nil {
return err
}
this.deleteByHashSQL = `DELETE FROM "` + this.itemsTableName + `" WHERE "hash"=?`
this.deleteByHashStmt, err = this.writeDB.Prepare(this.deleteByHashSQL)

View File

@@ -767,6 +767,7 @@ func (this *FileStorage) CleanAll() error {
}
}
var dirNameReg = regexp.MustCompile(`^[0-9a-f]{2}$`)
for _, rootDir := range rootDirs {
var dir = rootDir + "/p" + types.String(this.policy.Id)
fp, err := os.Open(dir)
@@ -795,11 +796,7 @@ func (this *FileStorage) CleanAll() error {
subDir := info.Name()
// 检查目录名
ok, err := regexp.MatchString(`^[0-9a-f]{2}$`, subDir)
if err != nil {
return err
}
if !ok {
if !dirNameReg.MatchString(subDir) {
continue
}