From 751132c73442e399ece56008c08d60e10cc59b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=83=E9=9A=A8=E7=B7=A3=E5=8B=95?= Date: Sat, 20 Sep 2025 01:39:47 +0800 Subject: [PATCH] v25.9.20 v25.9.20 --- database/history.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/database/history.go b/database/history.go index 67a88df9..e624025c 100644 --- a/database/history.go +++ b/database/history.go @@ -12,7 +12,7 @@ type LinkHistory struct { CreatedAt time.Time `gorm:"not null"` } -// AddLinkHistory adds a new link record and trims old ones +// AddLinkHistory adds a new link record, trims old ones, and ensures data is persisted. func AddLinkHistory(record *LinkHistory) error { // 1. Add the new record if err := db.Create(record).Error; err != nil { @@ -34,7 +34,10 @@ func AddLinkHistory(record *LinkHistory) error { } } } - return nil + + // 【核心修正】: 在所有数据库写入和删除操作完成后, + // 立即在此处调用 Checkpoint,确保本次操作被完整持久化到数据库文件。 + return Checkpoint() } // GetLinkHistory retrieves the 10 most recent link records @@ -46,3 +49,4 @@ func GetLinkHistory() ([]*LinkHistory, error) { } return histories, nil } +