mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-05 16:28:49 +01:00
🎨 Identify the database view whether is a "mirror" https://github.com/siyuan-note/siyuan/issues/9578
This commit is contained in:
parent
d5dfb2a732
commit
960cf3fe04
2 changed files with 27 additions and 0 deletions
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue