mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Synchronize the related entries when the database creates a two-way relation https://github.com/siyuan-note/siyuan/issues/11250 https://github.com/siyuan-note/siyuan/issues/11356
This commit is contained in:
parent
c197ca2018
commit
b042355363
2 changed files with 32 additions and 6 deletions
|
|
@ -1629,10 +1629,18 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
srcKeyValues := keyValues
|
for _, srcVal := range keyValues.Values {
|
||||||
for _, srcVal := range srcKeyValues.Values {
|
|
||||||
for _, blockID := range srcVal.Relation.BlockIDs {
|
for _, blockID := range srcVal.Relation.BlockIDs {
|
||||||
destVal := &av.Value{ID: ast.NewNodeID(), KeyID: destKeyValues.Key.ID, BlockID: blockID, Type: keyValues.Key.Type, Relation: &av.ValueRelation{}, CreatedAt: now, UpdatedAt: now + 1000}
|
destVal := destAv.GetValue(destKeyValues.Key.ID, blockID)
|
||||||
|
if nil == destVal {
|
||||||
|
destVal = &av.Value{ID: ast.NewNodeID(), KeyID: destKeyValues.Key.ID, BlockID: blockID, Type: keyValues.Key.Type, Relation: &av.ValueRelation{}, CreatedAt: now, UpdatedAt: now + 1000}
|
||||||
|
} else {
|
||||||
|
destVal.Type = keyValues.Key.Type
|
||||||
|
if nil == destVal.Relation {
|
||||||
|
destVal.Relation = &av.ValueRelation{}
|
||||||
|
}
|
||||||
|
destVal.UpdatedAt = now
|
||||||
|
}
|
||||||
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
|
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
|
||||||
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
|
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
|
||||||
destKeyValues.Values = append(destKeyValues.Values, destVal)
|
destKeyValues.Values = append(destKeyValues.Values, destVal)
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
||||||
}
|
}
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
|
|
||||||
zipPath = exportFolder + ".db.zip"
|
zipPath = getUniqueFilename(exportFolder + ".db.zip")
|
||||||
zip, err := gulu.Zip.Create(zipPath)
|
zip, err := gulu.Zip.Create(zipPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("create export .db.zip [%s] failed: %s", exportFolder, err)
|
logging.LogErrorf("create export .db.zip [%s] failed: %s", exportFolder, err)
|
||||||
|
|
@ -209,6 +209,24 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUniqueFilename(filePath string) string {
|
||||||
|
if !gulu.File.IsExist(filePath) {
|
||||||
|
return filePath
|
||||||
|
}
|
||||||
|
|
||||||
|
ext := filepath.Ext(filePath)
|
||||||
|
base := strings.TrimSuffix(filepath.Base(filePath), ext)
|
||||||
|
dir := filepath.Dir(filePath)
|
||||||
|
i := 1
|
||||||
|
for {
|
||||||
|
newPath := filepath.Join(dir, base+" ("+strconv.Itoa(i)+ext) + ")"
|
||||||
|
if !gulu.File.IsExist(newPath) {
|
||||||
|
return newPath
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Export2Liandi(id string) (err error) {
|
func Export2Liandi(id string) (err error) {
|
||||||
tree, err := LoadTreeByBlockID(id)
|
tree, err := LoadTreeByBlockID(id)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue