mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Improve Add to Database search sorting https://github.com/siyuan-note/siyuan/issues/10952
This commit is contained in:
parent
7d680ed391
commit
b3a2c49f15
3 changed files with 141 additions and 41 deletions
|
|
@ -26,41 +26,6 @@ import (
|
|||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
func BatchGetMirrorAttrViewBlockIDs(avIDs []string) (ret map[string]string) {
|
||||
av.AttributeViewBlocksLock.Lock()
|
||||
defer av.AttributeViewBlocksLock.Unlock()
|
||||
|
||||
ret = map[string]string{}
|
||||
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
if !filelock.IsExist(blocks) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(blocks)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
avBlocks := map[string][]string{}
|
||||
if err = msgpack.Unmarshal(data, &avBlocks); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, avID := range avIDs {
|
||||
blockIDs := avBlocks[avID]
|
||||
for _, blockID := range blockIDs {
|
||||
if nil != GetBlockTree(blockID) {
|
||||
ret[avID] = blockID
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetMirrorAttrViewBlockIDs(avID string) (ret []string) {
|
||||
av.AttributeViewBlocksLock.Lock()
|
||||
defer av.AttributeViewBlocksLock.Unlock()
|
||||
|
|
@ -91,3 +56,49 @@ 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 nil != err {
|
||||
logging.LogErrorf("read attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
avBlocks := map[string][]string{}
|
||||
if err = msgpack.Unmarshal(data, &avBlocks); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, avID := range avIDs {
|
||||
var blockIDs []string
|
||||
for _, blockID := range avBlocks[avID] {
|
||||
if nil == GetBlockTree(blockID) {
|
||||
continue
|
||||
}
|
||||
|
||||
blockIDs = append(blockIDs, blockID)
|
||||
}
|
||||
avBlock := &AvBlock{
|
||||
AvID: avID,
|
||||
BlockIDs: blockIDs,
|
||||
}
|
||||
ret = append(ret, avBlock)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue