♻️ Clean code

This commit is contained in:
Daniel 2024-03-10 23:27:13 +08:00
parent 9c512960bc
commit f3574038e2
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
28 changed files with 160 additions and 130 deletions

View file

@ -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")