mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 02:13:41 +09:00
GO-4577 Fix comments
This commit is contained in:
parent
57b9b65b33
commit
52ebc2226a
3 changed files with 75 additions and 24 deletions
|
@ -130,10 +130,7 @@ func (gr *Builder) buildGraph(
|
|||
edges = gr.appendRelations(rec, relations, edges, existedNodes, sourceId, outgoingRelationLink)
|
||||
var nodesToAdd []*types.Struct
|
||||
nodesToAdd, edges = gr.appendLinks(req.SpaceId, rec, outgoingRelationLink, existedNodes, edges, sourceId)
|
||||
|
||||
if len(nodesToAdd) != 0 {
|
||||
nodes = append(nodes, nodesToAdd...)
|
||||
}
|
||||
nodes = append(nodes, pbtypes.MapN(nodesToAdd, req.Keys...)...)
|
||||
}
|
||||
return nodes, edges
|
||||
}
|
||||
|
@ -209,29 +206,31 @@ func (gr *Builder) appendLinks(
|
|||
// ignore files because we index all file blocks as outgoing links
|
||||
continue
|
||||
case smartblock.SmartBlockTypeDate:
|
||||
details, err := gr.objectStore.SpaceIndex(spaceID).QueryByIds([]string{link})
|
||||
if err == nil && len(details) != 1 {
|
||||
err = fmt.Errorf("expected to get 1 date object, got %d", len(details))
|
||||
if _, exists := existedNodes[link]; !exists {
|
||||
details, err := gr.objectStore.SpaceIndex(spaceID).QueryByIds([]string{link})
|
||||
if err == nil && len(details) != 1 {
|
||||
err = fmt.Errorf("expected to get 1 date object, got %d", len(details))
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("get details of Date object", zap.String("objectId", link), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
existedNodes[link] = struct{}{}
|
||||
nodes = append(nodes, details[0].Details)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("get details of Date object", zap.String("objectId", link), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
existedNodes[link] = struct{}{}
|
||||
nodes = append(nodes, details[0].Details)
|
||||
}
|
||||
|
||||
if sbType != smartblock.SmartBlockTypeFileObject {
|
||||
if _, exists := outgoingRelationLink[link]; !exists {
|
||||
if _, exists := existedNodes[link]; exists {
|
||||
edges = append(edges, &pb.RpcObjectGraphEdge{
|
||||
Source: id,
|
||||
Target: link,
|
||||
Name: "",
|
||||
Type: pb.RpcObjectGraphEdge_Link,
|
||||
})
|
||||
}
|
||||
}
|
||||
if _, exists := outgoingRelationLink[link]; exists {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, exists := existedNodes[link]; exists {
|
||||
edges = append(edges, &pb.RpcObjectGraphEdge{
|
||||
Source: id,
|
||||
Target: link,
|
||||
Name: "",
|
||||
Type: pb.RpcObjectGraphEdge_Link,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nodes, edges
|
||||
|
|
|
@ -530,6 +530,13 @@ func Map(s *types.Struct, keys ...string) *types.Struct {
|
|||
return ns
|
||||
}
|
||||
|
||||
func MapN(structs []*types.Struct, keys ...string) []*types.Struct {
|
||||
for i, s := range structs {
|
||||
structs[i] = Map(s, keys...)
|
||||
}
|
||||
return structs
|
||||
}
|
||||
|
||||
func StructIterate(st *types.Struct, f func(path []string, v *types.Value)) {
|
||||
var iterate func(s *types.Struct, f func(path []string, v *types.Value), path []string)
|
||||
iterate = func(s *types.Struct, f func(path []string, v *types.Value), path []string) {
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"github.com/gogo/protobuf/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
|
@ -177,3 +179,46 @@ func TestIsEmptyValueOrAbsent(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapN(t *testing.T) {
|
||||
// given
|
||||
structs := []*types.Struct{
|
||||
{Fields: map[string]*types.Value{
|
||||
"name": String("obj1"),
|
||||
"id": String("obj1"),
|
||||
"key": String("obj1"),
|
||||
}},
|
||||
{Fields: map[string]*types.Value{
|
||||
"name": String("obj2"),
|
||||
"id": String("obj2"),
|
||||
"links": StringList([]string{"obj1", "obj3"}),
|
||||
}},
|
||||
{Fields: map[string]*types.Value{
|
||||
"name": String("obj3"),
|
||||
"id": String("obj3"),
|
||||
"number": Int64(42),
|
||||
}},
|
||||
}
|
||||
keys := []string{"name", "id"}
|
||||
|
||||
// when
|
||||
mapped := MapN(structs, keys...)
|
||||
|
||||
// then
|
||||
require.Len(t, mapped, 3)
|
||||
assert.Len(t, maps.Keys(mapped[0].Fields), 2)
|
||||
assert.Len(t, maps.Keys(mapped[1].Fields), 2)
|
||||
assert.Len(t, maps.Keys(mapped[2].Fields), 2)
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
a := 3
|
||||
switch a {
|
||||
case 1:
|
||||
fmt.Println("1")
|
||||
case 2:
|
||||
fmt.Println("2")
|
||||
default:
|
||||
fmt.Println("default")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue