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

This commit is contained in:
Daniel 2024-07-10 12:02:52 +08:00
parent f566ef4abc
commit e4541c9d5f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 6 additions and 6 deletions

View file

@ -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)) 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 return
} }
@ -619,7 +619,7 @@ func clearOutdatedHistoryDir(historyDir string) {
} }
// 清理历史库 // 清理历史库
sql.DeleteOutdatedHistories(fmt.Sprintf("%d", ago)) sql.DeleteOutdatedHistories(ago)
} }
var boxLatestHistoryTime = map[string]time.Time{} var boxLatestHistoryTime = map[string]time.Time{}

View file

@ -104,8 +104,8 @@ func queryHistory(query string, args ...interface{}) (*sql.Rows, error) {
return historyDB.Query(query, args...) return historyDB.Query(query, args...)
} }
func deleteOutdatedHistories(tx *sql.Tx, before string, context map[string]interface{}) (err error) { func deleteOutdatedHistories(tx *sql.Tx, before int64, context map[string]interface{}) (err error) {
stmt := "DELETE FROM histories_fts_case_insensitive WHERE created < ?" stmt := "DELETE FROM histories_fts_case_insensitive WHERE CAST(created AS INTEGER) < ?"
if err = execStmtTx(tx, stmt, before); nil != err { if err = execStmtTx(tx, stmt, before); nil != err {
return return
} }

View file

@ -41,7 +41,7 @@ type historyDBQueueOperation struct {
action string // index/deleteOutdated action string // index/deleteOutdated
histories []*History // index histories []*History // index
before string // deleteOutdated before int64 // deleteOutdated
} }
func FlushHistoryTxJob() { func FlushHistoryTxJob() {
@ -121,7 +121,7 @@ func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx, context map[string]i
return return
} }
func DeleteOutdatedHistories(before string) { func DeleteOutdatedHistories(before int64) {
historyDBQueueLock.Lock() historyDBQueueLock.Lock()
defer historyDBQueueLock.Unlock() defer historyDBQueueLock.Unlock()