mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 22:38:49 +01:00
🎨 Improve Add to Database https://github.com/siyuan-note/siyuan/issues/10659
This commit is contained in:
parent
6270d55fa3
commit
c7c7bdb950
2 changed files with 58 additions and 120 deletions
|
|
@ -55,50 +55,3 @@ func GetMirrorAttrViewBlockIDs(avID string) (ret []string) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
type AvBlock struct {
|
||||
AvID string
|
||||
BlockIDs []string
|
||||
}
|
||||
|
||||
func BatchGetMirrorAttrViewBlocks(avIDs []string) (ret []*AvBlock) {
|
||||
av.AttributeViewBlocksLock.Lock()
|
||||
defer av.AttributeViewBlocksLock.Unlock()
|
||||
|
||||
ret = []*AvBlock{}
|
||||
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
if !filelock.IsExist(blocks) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(blocks)
|
||||
if err != nil {
|
||||
logging.LogErrorf("read attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
avBlocks := map[string][]string{}
|
||||
if err = msgpack.Unmarshal(data, &avBlocks); err != nil {
|
||||
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, avID := range avIDs {
|
||||
var blockIDs []string
|
||||
bts := GetBlockTrees(avBlocks[avID])
|
||||
for blockID := range bts {
|
||||
blockIDs = append(blockIDs, blockID)
|
||||
}
|
||||
if 1 > len(blockIDs) {
|
||||
continue
|
||||
}
|
||||
|
||||
avBlock := &AvBlock{
|
||||
AvID: avID,
|
||||
BlockIDs: blockIDs,
|
||||
}
|
||||
ret = append(ret, avBlock)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue