Skip to content

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

:art: Improve av rollback

Daniela3fead2f3744
diff --git a/kernel/av/mirror.go b/kernel/av/mirror.go
index 95a0795a00..9b949faf30 100644
--- a/kernel/av/mirror.go
+++ b/kernel/av/mirror.go
@@ -17,6 +17,11 @@ var (
AttributeViewBlocksLock = sync.Mutex{}
)
+func GetAvBlocks(avID string) []string {
+ avBlocks := GetBlockRels()
+ return avBlocks[avID]
+}
+
func GetBlockRels() (ret map[string][]string) {
AttributeViewBlocksLock.Lock()
defer AttributeViewBlocksLock.Unlock()
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 3cc5c3b26e..db0a4a996e 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -56,6 +56,7 @@ import (
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
+ "github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/sql"
@@ -329,6 +330,22 @@ func RollbackRepoSnapshotFile(fileID string) (err error) {
return
}
+ if strings.HasPrefix(file.Path, "/storage/av/") && strings.HasSuffix(file.Path, ".json") {
+ avID := strings.TrimSuffix(filepath.Base(file.Path), ".json")
+ cache.RemoveAVData(avID)
+ blockIDs := av.GetAvBlocks(avID)
+ var reloadRootIDs []string
+ for _, blockID := range blockIDs {
+ if bt := treenode.GetBlockTree(blockID); nil != bt {
+ reloadRootIDs = append(reloadRootIDs, blockID)
+ }
+ }
+ reloadRootIDs = gulu.Str.RemoveDuplicatedElem(reloadRootIDs)
+ for _, id := range reloadRootIDs {
+ ReloadProtyle(id)
+ }
+ }
+
msg := fmt.Sprintf(Conf.Language(286), to)
util.PushMsg(msg, 7000)
}