diff --git a/internal/caches/list_file.go b/internal/caches/list_file.go index ce9c666..aef579a 100644 --- a/internal/caches/list_file.go +++ b/internal/caches/list_file.go @@ -261,11 +261,6 @@ func (this *FileList) Purge(count int, callback func(hash string) error) (int, e continue } - _, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`) - if err != nil { - return 0, err - } - countFound += len(hashStrings) // 不在 rows.Next() 循环中操作是为了避免死锁 @@ -280,6 +275,11 @@ func (this *FileList) Purge(count int, callback func(hash string) error) (int, e return 0, err } } + + _, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`) + if err != nil { + return 0, err + } } return countFound, nil @@ -301,11 +301,6 @@ func (this *FileList) PurgeLFU(count int, callback func(hash string) error) erro continue } - _, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`) - if err != nil { - return err - } - // 不在 rows.Next() 循环中操作是为了避免死锁 for _, hash := range hashStrings { _, err = this.remove(hash, true) @@ -318,6 +313,11 @@ func (this *FileList) PurgeLFU(count int, callback func(hash string) error) erro return err } } + + _, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`) + if err != nil { + return err + } } return nil }