mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
♻️ Clean code
This commit is contained in:
parent
9c512960bc
commit
f3574038e2
28 changed files with 160 additions and 130 deletions
|
|
@ -13,37 +13,12 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
attributeViewBlocksLock = sync.Mutex{}
|
||||
AttributeViewBlocksLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
func GetMirrorBlockIDs(avID string) []string {
|
||||
attributeViewBlocksLock.Lock()
|
||||
defer attributeViewBlocksLock.Unlock()
|
||||
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
if !filelock.IsExist(blocks) {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(blocks)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read attribute view blocks failed: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
avBlocks := map[string][]string{}
|
||||
if err = msgpack.Unmarshal(data, &avBlocks); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
blockIDs := avBlocks[avID]
|
||||
return blockIDs
|
||||
}
|
||||
|
||||
func IsMirror(avID string) bool {
|
||||
attributeViewBlocksLock.Lock()
|
||||
defer attributeViewBlocksLock.Unlock()
|
||||
AttributeViewBlocksLock.Lock()
|
||||
defer AttributeViewBlocksLock.Unlock()
|
||||
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
if !filelock.IsExist(blocks) {
|
||||
|
|
@ -67,8 +42,8 @@ func IsMirror(avID string) bool {
|
|||
}
|
||||
|
||||
func RemoveBlockRel(avID, blockID string) {
|
||||
attributeViewBlocksLock.Lock()
|
||||
defer attributeViewBlocksLock.Unlock()
|
||||
AttributeViewBlocksLock.Lock()
|
||||
defer AttributeViewBlocksLock.Unlock()
|
||||
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
if !filelock.IsExist(blocks) {
|
||||
|
|
@ -112,8 +87,8 @@ func RemoveBlockRel(avID, blockID string) {
|
|||
}
|
||||
|
||||
func UpsertBlockRel(avID, blockID string) {
|
||||
attributeViewBlocksLock.Lock()
|
||||
defer attributeViewBlocksLock.Unlock()
|
||||
AttributeViewBlocksLock.Lock()
|
||||
defer AttributeViewBlocksLock.Unlock()
|
||||
|
||||
avBlocks := map[string][]string{}
|
||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue