An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: List file/asset history following the limit of editor history retention days https://github.com/siyuan-note/siyuan/issues/9723
Danielf5205d846ccc
diff --git a/kernel/model/history.go b/kernel/model/history.goindex caba1466bf..3ea03afb52 100644--- a/kernel/model/history.go+++ b/kernel/model/history.go@@ -500,6 +500,7 @@ func clearOutdatedHistoryDir(historyDir string) {}now := time.Now()+ ago := now.Add(-24 * time.Hour * time.Duration(Conf.Editor.HistoryRetentionDays)).Unix()var removes []stringfor _, dir := range dirs {dirInfo, err := dir.Info()@@ -507,7 +508,7 @@ func clearOutdatedHistoryDir(historyDir string) {logging.LogErrorf("read history dir [%s] failed: %s", dir.Name(), err)continue}- if Conf.Editor.HistoryRetentionDays < int(now.Sub(dirInfo.ModTime()).Hours()/24) {+ if dirInfo.ModTime().Unix() < ago {removes = append(removes, filepath.Join(historyDir, dir.Name()))}}@@ -517,10 +518,10 @@ func clearOutdatedHistoryDir(historyDir string) {continue}//logging.LogInfof("auto removed history dir [%s]", dir)-- // 清理历史库- sql.DeleteHistoriesByPathPrefixQueue(dir)}++ // 清理历史库+ sql.DeleteOutdatedHistories(fmt.Sprintf("%d", ago))}var boxLatestHistoryTime = map[string]time.Time{}diff --git a/kernel/sql/history.go b/kernel/sql/history.goindex a74a4c210d..a53b48f99c 100644--- a/kernel/sql/history.go+++ b/kernel/sql/history.go@@ -104,9 +104,9 @@ func queryHistory(query string, args ...interface{}) (*sql.Rows, error) {return historyDB.Query(query, args...)}-func deleteHistoriesByPathPrefix(tx *sql.Tx, pathPrefix string, context map[string]interface{}) (err error) {- stmt := "DELETE FROM histories_fts_case_insensitive WHERE path LIKE ?"- if err = execStmtTx(tx, stmt, pathPrefix+"%"); nil != err {+func deleteOutdatedHistories(tx *sql.Tx, before string, context map[string]interface{}) (err error) {+ stmt := "DELETE FROM histories_fts_case_insensitive WHERE created < ?"+ if err = execStmtTx(tx, stmt, before); nil != err {return}returndiff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.goindex 32a3a3be60..74fc2e1604 100644--- a/kernel/sql/queue_history.go+++ b/kernel/sql/queue_history.go@@ -39,10 +39,10 @@ var (type historyDBQueueOperation struct {inQueueTime time.Time- action string // index/deletePathPrefix+ action string // index/deleteOutdated- histories []*History // index- pathPrefix string // deletePathPrefix+ histories []*History // index+ before string // deleteOutdated}func FlushHistoryTxJob() {@@ -111,8 +111,8 @@ func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx, context map[string]iswitch op.action {case "index":err = insertHistories(tx, op.histories, context)- case "deletePathPrefix":- err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, context)+ case "deleteOutdated":+ err = deleteOutdatedHistories(tx, op.before, context)default:msg := fmt.Sprintf("unknown history operation [%s]", op.action)logging.LogErrorf(msg)@@ -121,11 +121,11 @@ func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx, context map[string]ireturn}-func DeleteHistoriesByPathPrefixQueue(pathPrefix string) {+func DeleteOutdatedHistories(before string) {historyDBQueueLock.Lock()defer historyDBQueueLock.Unlock()- newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deletePathPrefix", pathPrefix: pathPrefix}+ newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deleteOutdated", before: before}historyOperationQueue = append(historyOperationQueue, newOp)}