Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: After changing the `History Retention Days`, the file history cannot be displayed https://github.com/siyuan-note/siyuan/issues/11935

Daniele4541c9d5fb8
diff --git a/kernel/model/history.go b/kernel/model/history.go
index b0ce07e38c..e339434af5 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -446,7 +446,7 @@ func buildSearchHistoryQueryFilter(query, op, box, table string, typ int) (stmt
}
ago := time.Now().Add(-24 * time.Hour * time.Duration(Conf.Editor.HistoryRetentionDays))
- stmt += " AND created > '" + fmt.Sprintf("%d", ago.Unix()) + "'"
+ stmt += " AND CAST(created AS INTEGER) > " + fmt.Sprintf("%d", ago.Unix()) + ""
return
}
@@ -619,7 +619,7 @@ func clearOutdatedHistoryDir(historyDir string) {
}
// 清理历史库
- sql.DeleteOutdatedHistories(fmt.Sprintf("%d", ago))
+ sql.DeleteOutdatedHistories(ago)
}
var boxLatestHistoryTime = map[string]time.Time{}
diff --git a/kernel/sql/history.go b/kernel/sql/history.go
index a53b48f99c..5a1dd27605 100644
--- a/kernel/sql/history.go
+++ b/kernel/sql/history.go
@@ -104,8 +104,8 @@ func queryHistory(query string, args ...interface{}) (*sql.Rows, error) {
return historyDB.Query(query, args...)
}
-func deleteOutdatedHistories(tx *sql.Tx, before string, context map[string]interface{}) (err error) {
- stmt := "DELETE FROM histories_fts_case_insensitive WHERE created < ?"
+func deleteOutdatedHistories(tx *sql.Tx, before int64, context map[string]interface{}) (err error) {
+ stmt := "DELETE FROM histories_fts_case_insensitive WHERE CAST(created AS INTEGER) < ?"
if err = execStmtTx(tx, stmt, before); nil != err {
return
}
diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go
index 418a821600..b9643210ac 100644
--- a/kernel/sql/queue_history.go
+++ b/kernel/sql/queue_history.go
@@ -41,7 +41,7 @@ type historyDBQueueOperation struct {
action string // index/deleteOutdated
histories []*History // index
- before string // deleteOutdated
+ before int64 // deleteOutdated
}
func FlushHistoryTxJob() {
@@ -121,7 +121,7 @@ func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx, context map[string]i
return
}
-func DeleteOutdatedHistories(before string) {
+func DeleteOutdatedHistories(before int64) {
historyDBQueueLock.Lock()
defer historyDBQueueLock.Unlock()