🎨 Identify the database view whether is a "mirror" https://github.com/siyuan-note/siyuan/issues/9578

This commit is contained in:
Daniel 2023-11-02 16:05:35 +08:00
parent d5dfb2a732
commit 960cf3fe04
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 27 additions and 0 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -60,6 +61,7 @@ func renderAttributeView(c *gin.Context) {
"viewID": view.GetID(),
"views": views,
"view": view,
"isMirror": av.IsMirror(attrView.ID),
}
}

View file

@ -590,6 +590,31 @@ var (
attributeViewBlocksLock = sync.Mutex{}
)
func IsMirror(avID string) bool {
attributeViewBlocksLock.Lock()
defer attributeViewBlocksLock.Unlock()
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
if !gulu.File.IsExist(blocks) {
return false
}
data, err := filelock.ReadFile(blocks)
if nil != err {
logging.LogErrorf("read attribute view blocks failed: %s", err)
return false
}
avBlocks := map[string][]string{}
if err = msgpack.Unmarshal(data, &avBlocks); nil != err {
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
return false
}
blockIDs := avBlocks[avID]
return nil != blockIDs && 1 < len(blockIDs)
}
func RemoveBlockRel(avID, blockID string) {
attributeViewBlocksLock.Lock()
defer attributeViewBlocksLock.Unlock()