From b959cc2beb684567ced727b4a3996dff944b7d51 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 12 May 2024 22:45:04 +0800 Subject: [PATCH 1/2] :art: Refresh virtual block ref when closing box https://github.com/siyuan-note/siyuan/issues/11149#issuecomment-2106254491 --- app/appearance/langs/en_US.json | 3 ++- app/appearance/langs/es_ES.json | 3 ++- app/appearance/langs/fr_FR.json | 3 ++- app/appearance/langs/ja_JP.json | 3 ++- app/appearance/langs/zh_CHT.json | 3 ++- app/appearance/langs/zh_CN.json | 3 ++- kernel/model/index.go | 5 +++++ kernel/model/virutalref.go | 10 +++++++++- kernel/task/queue.go | 1 + 9 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 185de331d..e9a872182 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1236,7 +1236,8 @@ "task.database.index.embedBlock": "Execute database index embed block", "task.reload.ui": "Execute reload UI", "task.asset.database.index.full": "Execute asset database rebuild index", - "task.asset.database.index.commit": "Execute asset database index commit" + "task.asset.database.index.commit": "Execute asset database index commit", + "task.cache.virtualBlockRef": "Execute cache virtual reference" }, "_trayMenu": { "showWindow": "Show Window", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index e2cb56716..eb4575ed4 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1236,7 +1236,8 @@ "task.database.index.embedBlock": "Ejecutar bloque de incrustación de índice de base de datos", "task.reload.ui": "IU de recarga de tareas", "task.asset.database.index.full": "Ejecutar índice de reconstrucción de base de datos de activos", - "task.asset.database.index.commit": "Ejecutar confirmación del índice de la base de datos de activos" + "task.asset.database.index.commit": "Ejecutar confirmación del índice de la base de datos de activos", + "task.cache.virtualBlockRef": "Ejecutar referencia virtual de caché" }, "_trayMenu": { "showWindow": "Mostrar ventana", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index e3f511fb6..20b5f6d2f 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1236,7 +1236,8 @@ "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", "task.asset.database.index.full": "Exécuter l'index de reconstruction de la base de données d'actifs", - "task.asset.database.index.commit": "Exécuter la validation de l'index de la base de données des actifs" + "task.asset.database.index.commit": "Exécuter la validation de l'index de la base de données des actifs", + "task.cache.virtualBlockRef": "Effectuer une référence virtuelle du cache" }, "_trayMenu": { "showWindow": "Afficher la fenêtre principale", diff --git a/app/appearance/langs/ja_JP.json b/app/appearance/langs/ja_JP.json index f97314b3e..ac56ff506 100644 --- a/app/appearance/langs/ja_JP.json +++ b/app/appearance/langs/ja_JP.json @@ -1236,7 +1236,8 @@ "task.database.index.embedBlock": "データベースのインデックスを埋め込みブロック中", "task.reload.ui": "UI の再読み込み中", "task.asset.database.index.full": "アセットデータベースのインデックスを再構築中", - "task.asset.database.index.commit": "アセットデータベースのインデックスをコミット中" + "task.asset.database.index.commit": "アセットデータベースのインデックスをコミット中", + "task.cache.virtualBlockRef": "キャッシュ仮想参照を実行" }, "_trayMenu": { "showWindow": "ウィンドウを表示", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 89c152fef..bb81e2732 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1236,7 +1236,8 @@ "task.database.index.embedBlock": "執行資料庫索引嵌入塊", "task.reload.ui": "執行重載界面", "task.asset.database.index.full": "執行資源文件數據庫重建索引", - "task.asset.database.index.commit": "執行資源文件數據庫索引提交" + "task.asset.database.index.commit": "執行資源文件數據庫索引提交", + "task.cache.virtualBlockRef": "執行快取虛擬引用" }, "_trayMenu": { "showWindow": "顯示主窗口", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 238f2f4ad..176b1851c 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1236,7 +1236,8 @@ "task.database.index.embedBlock": "执行数据库索引嵌入块", "task.reload.ui": "执行重载界面", "task.asset.database.index.full": "执行资源文件数据库重建索引", - "task.asset.database.index.commit": "执行资源文件数据库索引提交" + "task.asset.database.index.commit": "执行资源文件数据库索引提交", + "task.cache.virtualBlockRef": "执行缓存虚拟引用" }, "_trayMenu": { "showWindow": "显示主窗口", diff --git a/kernel/model/index.go b/kernel/model/index.go index d82c9e3b7..9a65a2b95 100644 --- a/kernel/model/index.go +++ b/kernel/model/index.go @@ -112,6 +112,11 @@ func unindex(boxID string) { ids := treenode.RemoveBlockTreesByBoxID(boxID) RemoveRecentDoc(ids) sql.DeleteBoxQueue(boxID) + + go func() { + sql.WaitForWritingDatabase() + ResetVirtualBlockRefCache() + }() } func (box *Box) Index() { diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index 9ff20fbbd..f68b3c7bb 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -31,6 +31,7 @@ import ( "github.com/dgraph-io/ristretto" "github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/sql" + "github.com/siyuan-note/siyuan/kernel/task" "github.com/siyuan-note/siyuan/kernel/treenode" ) @@ -99,6 +100,13 @@ func putBlockVirtualRefKeywords(blockContent string, root *ast.Node) (ret []stri } func CacheVirtualBlockRefJob() { + if !Conf.Editor.VirtualBlockRef { + return + } + task.AppendTask(task.CacheVirtualBlockRef, ResetVirtualBlockRefCache) +} + +func cacheVirtualBlockRef() { virtualBlockRefCache.Del("virtual_ref") if !Conf.Editor.VirtualBlockRef { return @@ -110,7 +118,7 @@ func CacheVirtualBlockRefJob() { func ResetVirtualBlockRefCache() { virtualBlockRefCache.Clear() - CacheVirtualBlockRefJob() + cacheVirtualBlockRef() } func AddVirtualBlockRefInclude(keyword []string) { diff --git a/kernel/task/queue.go b/kernel/task/queue.go index f92244dee..1e6d2e32e 100644 --- a/kernel/task/queue.go +++ b/kernel/task/queue.go @@ -99,6 +99,7 @@ const ( ReloadUI = "task.reload.ui" // 重载 UI AssetContentDatabaseIndexFull = "task.asset.database.index.full" // 资源文件数据库重建索引 AssetContentDatabaseIndexCommit = "task.asset.database.index.commit" // 资源文件数据库索引提交 + CacheVirtualBlockRef = "task.cache.virtualBlockRef" // 缓存虚拟块引用 ) // uniqueActions 描述了唯一的任务,即队列中只能存在一个在执行的任务。 From 60380f5deeb6e55da00e3a826d836e5698c74aef Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 12 May 2024 23:04:00 +0800 Subject: [PATCH 2/2] :art: Refresh virtual block ref when closing box https://github.com/siyuan-note/siyuan/issues/11149#issuecomment-2106254491 --- kernel/model/box.go | 4 ++++ kernel/model/index.go | 19 ++++++++++--------- kernel/model/repository.go | 5 +++++ kernel/model/virutalref.go | 9 ++------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/kernel/model/box.go b/kernel/model/box.go index cb958c483..fa56aa567 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -503,6 +503,10 @@ func genTreeID(tree *parse.Tree) { func FullReindex() { task.AppendTask(task.DatabaseIndexFull, fullReindex) task.AppendTask(task.DatabaseIndexRef, IndexRefs) + go func() { + sql.WaitForWritingDatabase() + ResetVirtualBlockRefCache() + }() task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, autoIndexEmbedBlock) cache.ClearDocsIAL() cache.ClearBlocksIAL() diff --git a/kernel/model/index.go b/kernel/model/index.go index 9a65a2b95..600554c3b 100644 --- a/kernel/model/index.go +++ b/kernel/model/index.go @@ -106,23 +106,26 @@ func listSyFiles(dir string) (ret []string) { func (box *Box) Unindex() { task.AppendTask(task.DatabaseIndex, unindex, box.ID) -} - -func unindex(boxID string) { - ids := treenode.RemoveBlockTreesByBoxID(boxID) - RemoveRecentDoc(ids) - sql.DeleteBoxQueue(boxID) - go func() { sql.WaitForWritingDatabase() ResetVirtualBlockRefCache() }() } +func unindex(boxID string) { + ids := treenode.RemoveBlockTreesByBoxID(boxID) + RemoveRecentDoc(ids) + sql.DeleteBoxQueue(boxID) +} + func (box *Box) Index() { task.AppendTask(task.DatabaseIndexRef, removeBoxRefs, box.ID) task.AppendTask(task.DatabaseIndex, index, box.ID) task.AppendTask(task.DatabaseIndexRef, IndexRefs) + go func() { + sql.WaitForWritingDatabase() + ResetVirtualBlockRefCache() + }() } func removeBoxRefs(boxID string) { @@ -286,8 +289,6 @@ func IndexRefs() { } logging.LogInfof("resolved refs [%d] in [%dms]", size, time.Now().Sub(start).Milliseconds()) util.PushStatusBar(fmt.Sprintf(Conf.Language(55), i)) - - ResetVirtualBlockRefCache() } var indexEmbedBlockLock = sync.Mutex{} diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 17c90399d..d88991db3 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -51,6 +51,7 @@ import ( "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/conf" "github.com/siyuan-note/siyuan/kernel/filesys" + "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/task" "github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/util" @@ -649,6 +650,10 @@ func checkoutRepo(id string) { task.AppendTask(task.DatabaseIndexFull, fullReindex) task.AppendTask(task.DatabaseIndexRef, IndexRefs) + go func() { + sql.WaitForWritingDatabase() + ResetVirtualBlockRefCache() + }() task.AppendTask(task.ReloadUI, util.ReloadUIResetScroll) if syncEnabled { diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index f68b3c7bb..e1ba2f4fe 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -106,8 +106,8 @@ func CacheVirtualBlockRefJob() { task.AppendTask(task.CacheVirtualBlockRef, ResetVirtualBlockRefCache) } -func cacheVirtualBlockRef() { - virtualBlockRefCache.Del("virtual_ref") +func ResetVirtualBlockRefCache() { + virtualBlockRefCache.Clear() if !Conf.Editor.VirtualBlockRef { return } @@ -116,11 +116,6 @@ func cacheVirtualBlockRef() { virtualBlockRefCache.Set("virtual_ref", keywords, 1) } -func ResetVirtualBlockRefCache() { - virtualBlockRefCache.Clear() - cacheVirtualBlockRef() -} - func AddVirtualBlockRefInclude(keyword []string) { if 1 > len(keyword) { return