Skip to content

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

:art: Improve history database index https://github.com/siyuan-note/siyuan/issues/8506

Daniel073af9a310bf
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 8ee04d7f85..2ffb68e6ed 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -943,6 +943,7 @@
"task.database.index.fix": "Execute database index fix",
"task.ocr.image": "Execute image OCR to extract text",
"task.history.generateDoc": "Execute GenerateDoc History",
+ "task.history.database.index.full": "Execute history database rebuild index",
"task.history.database.index.commit": "Execute history database index commit",
"task.database.index.embedBlock": "Execute database index embed block",
"task.reload.ui": "Execute reload UI",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index cbf74c8a1c..952e13da4a 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -943,6 +943,7 @@
"task.database.index.fix": "Ejecutar corrección del índice de la base de datos",
"task.ocr.image": "Ejecutar OCR de imagen para extraer texto",
"task.history.generateDoc": "Ejecutar Historial GenerateDoc",
+ "task.history.database.index.full": "Ejecutar el índice de reconstrucción de la base de datos del historial",
"task.history.database.index.commit": "Ejecutar la confirmación del índice de la base de datos del historial",
"task.database.index.embedBlock": "Ejecutar bloque de incrustación de índice de base de datos",
"task.reload.ui": "IU de recarga de tareas",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 8f0ef46456..c78568a391 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -943,6 +943,7 @@
"task.database.index.fix": "Effectuer la correction de l'index de la base de données",
"task.ocr.image": "Exécute l'OCR d'image pour extraire le texte",
"task.history.generateDoc": "Exécuter l'historique de GenerateDoc",
+ "task.history.database.index.full": "Exécuter l'index de reconstruction de la base de données de l'historique",
"task.history.database.index.commit": "Effectuer la validation de l'index de la base de données d'historique",
"task.database.index.embedBlock": "Exécuter le bloc d'intégration d'index de base de données",
"task.reload.ui": "Interface utilisateur de rechargement de tâche",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 304930caa5..1f74477c7e 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -943,6 +943,7 @@
"task.database.index.fix": "執行數據庫索引訂正",
"task.ocr.image": "執行圖片 OCR 提取文本",
"task.history.generateDoc": "執行生成文件歷史",
+ "task.history.database.index.full": "執行歷史數據庫重建索引",
"task.history.database.index.commit": "執行歷史數據庫索引提交",
"task.database.index.embedBlock": "執行數據庫索引嵌入塊",
"task.reload.ui": "執行重載界面",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index e315812a06..48df049c26 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -943,6 +943,7 @@
"task.database.index.fix": "执行数据库索引订正",
"task.ocr.image": "执行图片 OCR 提取文本",
"task.history.generateDoc": "执行生成文件历史",
+ "task.history.database.index.full": "执行历史数据库重建索引",
"task.history.database.index.commit": "执行历史数据库索引提交",
"task.database.index.embedBlock": "执行数据库索引嵌入块",
"task.reload.ui": "执行重载界面",
diff --git a/kernel/api/history.go b/kernel/api/history.go
index 712d712e3c..fce014e399 100644
--- a/kernel/api/history.go
+++ b/kernel/api/history.go
@@ -96,12 +96,7 @@ func reindexHistory(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
- err := model.ReindexHistory()
- if nil != err {
- ret.Code = -1
- ret.Msg = err.Error()
- return
- }
+ model.ReindexHistory()
}
func getNotebookHistory(c *gin.Context) {
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 85c7ba4d47..5a537b27bb 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -564,7 +564,12 @@ func getHistoryDir(suffix string, t time.Time) (ret string, err error) {
return
}
-func ReindexHistory() (err error) {
+func ReindexHistory() {
+ task.AppendTask(task.HistoryDatabaseIndexFull, fullReindexHistory)
+ return
+}
+
+func fullReindexHistory() {
historyDirs, err := os.ReadDir(util.HistoryDir)
if nil != err {
logging.LogErrorf("read history dir [%s] failed: %s", util.HistoryDir, err)
diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go
index b3cbfdfea5..3ee8a42fbc 100644
--- a/kernel/sql/queue_history.go
+++ b/kernel/sql/queue_history.go
@@ -83,7 +83,8 @@ func FlushHistoryQueue() {
if err = execHistoryOp(op, tx, context); nil != err {
tx.Rollback()
logging.LogErrorf("queue operation failed: %s", err)
- continue
+ util.PushMsg("History database index failed, please try to manually rebuild it in [Data history - File history]", 5000)
+ return
}
if err = commitHistoryTx(tx); nil != err {
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index facd623f41..1937010ff1 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -90,6 +90,7 @@ const (
DatabaseIndexFix = "task.database.index.fix" // 数据库索引订正
OCRImage = "task.ocr.image" // 图片 OCR 提取文本
HistoryGenerateDoc = "task.history.generateDoc" // 生成文件历史
+ HistoryDatabaseIndexFull = "task.history.database.index.full" // 历史数据库重建索引
HistoryDatabaseIndexCommit = "task.history.database.index.commit" // 历史数据库索引提交
DatabaseIndexEmbedBlock = "task.database.index.embedBlock" // 数据库索引嵌入块
ReloadUI = "task.reload.ui" // 重载 UI
@@ -103,6 +104,7 @@ var uniqueActions = []string{
DatabaseIndexCommit,
OCRImage,
HistoryGenerateDoc,
+ HistoryDatabaseIndexFull,
HistoryDatabaseIndexCommit,
DatabaseIndexEmbedBlock,
}