1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

Merge pull request #2461 from anyproto/go-4295-check-relation-key-on-import

GO-4295 Ignore relations with existing key
This commit is contained in:
Kirill Stonozhenko 2025-06-06 19:19:32 +02:00 committed by GitHub
commit c25be754d7
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 21 deletions

View file

@ -73,8 +73,9 @@ func TestDerivedObject_GetIDAndPayload(t *testing.T) {
Snapshot: &common.SnapshotModel{
Data: &common.StateSnapshot{
Details: domain.NewDetailsFromMap(map[domain.RelationKey]domain.Value{
bundle.RelationKeyName: domain.String("name"),
bundle.RelationKeyName: domain.String("IMPORTED NAME"),
bundle.RelationKeyRelationFormat: domain.Int64(int64(model.RelationFormat_number)),
bundle.RelationKeyRelationKey: domain.String(bundle.RelationKeyName.String()),
}),
},
SbType: coresb.SmartBlockTypeRelation,
@ -88,6 +89,7 @@ func TestDerivedObject_GetIDAndPayload(t *testing.T) {
bundle.RelationKeyUniqueKey: domain.String(uniqueKey.Marshal()),
bundle.RelationKeyId: domain.String("oldId"),
bundle.RelationKeyName: domain.String("name"),
bundle.RelationKeyRelationKey: domain.String(bundle.RelationKeyName.String()),
bundle.RelationKeyRelationFormat: domain.Int64(int64(model.RelationFormat_number)),
bundle.RelationKeyResolvedLayout: domain.Int64(int64(model.ObjectType_relation)),
bundle.RelationKeySpaceId: domain.String("spaceId"),

View file

@ -126,29 +126,32 @@ func (e *existingObject) getExistingRelationOption(snapshot *common.Snapshot, sp
}
func (e *existingObject) getExistingRelation(snapshot *common.Snapshot, spaceID string) string {
name := snapshot.Snapshot.Data.Details.GetString(bundle.RelationKeyName)
format := snapshot.Snapshot.Data.Details.GetFloat64(bundle.RelationKeyRelationFormat)
ids, _, err := e.objectStore.SpaceIndex(spaceID).QueryObjectIds(database.Query{
Filters: []database.FilterRequest{
{
Condition: model.BlockContentDataviewFilter_Equal,
RelationKey: bundle.RelationKeyName,
Value: domain.String(name),
records, err := e.objectStore.SpaceIndex(spaceID).QueryRaw(&database.Filters{FilterObj: database.FiltersAnd{
database.FilterEq{
Key: bundle.RelationKeyRelationFormat,
Cond: model.BlockContentDataviewFilter_Equal,
Value: snapshot.Snapshot.Data.Details.Get(bundle.RelationKeyRelationFormat),
},
database.FilterEq{
Key: bundle.RelationKeyResolvedLayout,
Cond: model.BlockContentDataviewFilter_Equal,
Value: domain.Int64(model.ObjectType_relation),
},
database.FiltersOr{
database.FilterEq{
Key: bundle.RelationKeyName,
Cond: model.BlockContentDataviewFilter_Equal,
Value: snapshot.Snapshot.Data.Details.Get(bundle.RelationKeyName),
},
{
Condition: model.BlockContentDataviewFilter_Equal,
RelationKey: bundle.RelationKeyRelationFormat,
Value: domain.Float64(format),
},
{
Condition: model.BlockContentDataviewFilter_Equal,
RelationKey: bundle.RelationKeyResolvedLayout,
Value: domain.Int64(model.ObjectType_relation),
database.FilterEq{
Key: bundle.RelationKeyRelationKey,
Cond: model.BlockContentDataviewFilter_Equal,
Value: snapshot.Snapshot.Data.Details.Get(bundle.RelationKeyRelationKey),
},
},
})
if err == nil && len(ids) > 0 {
return ids[0]
}}, 1, 0)
if err == nil && len(records) > 0 {
return records[0].Details.GetString(bundle.RelationKeyId)
}
return ""
}