From 7f3e6ddc656eb2537071fc2359a44fc18ce36d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 11 Oct 2023 06:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=BC=93=E5=AD=98Key=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=88=97=E8=A1=A8=E5=88=A0=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=BF=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 }