🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958

This commit is contained in:
Daniel 2024-01-01 00:28:34 +08:00
parent 77c4ccaa68
commit 3d3b2df07a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -217,30 +217,32 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
newPath := filepath.Join(filepath.Dir(path), newAvID+".json")
renameAvPaths[path] = newPath
avIDs[oldAvID] = newAvID
// 将数据库文件中的块 ID 替换为新的块 ID
data, readErr := os.ReadFile(path)
if nil != readErr {
logging.LogErrorf("read av file [%s] failed: %s", path, readErr)
return nil
}
var newData []byte
newData = data
for oldID, newID := range avBlockIDs {
newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
}
newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
if !bytes.Equal(data, newData) {
if writeErr := os.WriteFile(path, newData, 0644); nil != writeErr {
logging.LogErrorf("write av file [%s] failed: %s", path, writeErr)
return nil
}
}
return nil
})
// 重命名数据库文件
for oldPath, newPath := range renameAvPaths {
data, readErr := os.ReadFile(oldPath)
if nil != readErr {
logging.LogErrorf("read av file [%s] failed: %s", oldPath, readErr)
return nil
}
// 将数据库文件中的块 ID 替换为新的块 ID
newData := data
for oldAvID, newAvID := range avIDs {
for oldID, newID := range avBlockIDs {
newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
}
newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
}
if !bytes.Equal(data, newData) {
if writeErr := os.WriteFile(oldPath, newData, 0644); nil != writeErr {
logging.LogErrorf("write av file [%s] failed: %s", oldPath, writeErr)
return nil
}
}
if err = os.Rename(oldPath, newPath); nil != err {
logging.LogErrorf("rename av file from [%s] to [%s] failed: %s", oldPath, newPath, err)
return