From f25de8d5c9460eb99e38bd1bacd48ec287e6d96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 17 Dec 2021 11:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=B8=85=E9=99=A4=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E5=BB=B6=E6=97=B6=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/caches/list_file.go b/internal/caches/list_file.go index 35f6cfc..4f42399 100644 --- a/internal/caches/list_file.go +++ b/internal/caches/list_file.go @@ -9,10 +9,10 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/ttlcache" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/types" timeutil "github.com/iwind/TeaGo/utils/time" _ "github.com/mattn/go-sqlite3" "os" - "strconv" "strings" "sync/atomic" "time" @@ -255,8 +255,9 @@ func (this *FileList) CleanPrefix(prefix string) error { }() var count = int64(10000) + var staleLife = 600 // TODO 需要可以设置 for { - result, err := this.db.Exec(`UPDATE "`+this.itemsTableName+`" SET expiredAt=0 WHERE id IN (SELECT id FROM "`+this.itemsTableName+`" WHERE expiredAt>0 AND createdAt<=? AND INSTR("key", ?)=1 LIMIT `+strconv.FormatInt(count, 10)+`)`, utils.UnixTime(), prefix) + result, err := this.db.Exec(`UPDATE "`+this.itemsTableName+`" SET expiredAt=0,staleAt=? WHERE id IN (SELECT id FROM "`+this.itemsTableName+`" WHERE expiredAt>0 AND createdAt<=? AND INSTR("key", ?)=1 LIMIT `+types.String(count)+`)`, utils.UnixTime()+int64(staleLife), utils.UnixTime(), prefix) if err != nil { return err }