From 2f685063594c55edd5fca57264a5561db2a2c6a4 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 25 Apr 2023 18:17:59 +0200 Subject: [PATCH] GO-501: Get object info directly without doc service --- core/block/doc/service.go | 18 +++--------------- core/block/editor.go | 11 ----------- core/indexer/full_text.go | 2 +- core/indexer/indexer.go | 22 ++++++++++++++++------ 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/core/block/doc/service.go b/core/block/doc/service.go index 3697c4e80..a1ebaf6c4 100644 --- a/core/block/doc/service.go +++ b/core/block/doc/service.go @@ -2,15 +2,14 @@ package doc import ( "context" - "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/treegetter" "sync" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" - "github.com/gogo/protobuf/types" - "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/commonspace/object/treegetter" + "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/recordsbatcher" + "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" "github.com/anytypeio/go-anytype-middleware/pkg/lib/logging" "github.com/anytypeio/go-anytype-middleware/util/slice" ) @@ -32,15 +31,9 @@ type DocInfo struct { State *state.State } -type RelationOptionsInfo struct { - RelationId string - Options []*types.Struct -} - type OnDocChangeCallback func(ctx context.Context, info DocInfo) error type Service interface { - GetDocInfo(ctx context.Context, id string) (info DocInfo, err error) OnWholeChange(cb OnDocChangeCallback) ReportChange(ctx context.Context, info DocInfo) WakeupIds(ids ...string) @@ -49,7 +42,6 @@ type Service interface { } type docInfoHandler interface { - GetDocInfo(ctx context.Context, id string) (info DocInfo, err error) Wakeup(id string) (err error) } @@ -98,10 +90,6 @@ func (l *listener) WakeupIds(ids ...string) { } } -func (l *listener) GetDocInfo(ctx context.Context, id string) (info DocInfo, err error) { - return l.docInfoHandler.GetDocInfo(ctx, id) -} - func (l *listener) wakeupLoop() { var buf = make([]interface{}, 50) var idsToWakeup []string diff --git a/core/block/editor.go b/core/block/editor.go index 7ead91fb2..f97241c66 100644 --- a/core/block/editor.go +++ b/core/block/editor.go @@ -8,7 +8,6 @@ import ( "github.com/gogo/protobuf/types" ds "github.com/ipfs/go-datastore" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" "github.com/anytypeio/go-anytype-middleware/core/block/editor" "github.com/anytypeio/go-anytype-middleware/core/block/editor/basic" "github.com/anytypeio/go-anytype-middleware/core/block/editor/bookmark" @@ -590,16 +589,6 @@ func (s *Service) AddRelationBlock(ctx *session.Context, req pb.RpcBlockRelation }) } -func (s *Service) GetDocInfo(ctx context.Context, id string) (info doc.DocInfo, err error) { - if err = s.DoWithContext(ctx, id, func(b smartblock.SmartBlock) error { - info, err = b.GetDocInfo() - return err - }); err != nil { - return - } - return -} - func (s *Service) Wakeup(id string) (err error) { return s.Do(id, func(b smartblock.SmartBlock) error { return nil diff --git a/core/indexer/full_text.go b/core/indexer/full_text.go index 85636e7cb..c94d777a1 100644 --- a/core/indexer/full_text.go +++ b/core/indexer/full_text.go @@ -52,7 +52,7 @@ func (i *indexer) ftIndexDoc(id string, _ time.Time) (err error) { // ctx := context.WithValue(context.Background(), ocache.CacheTimeout, cacheTimeout) ctx := context.WithValue(context.Background(), metrics.CtxKeyRequest, "index_fulltext") - info, err := i.doc.GetDocInfo(ctx, id) + info, err := i.getObjectInfo(ctx, id) if err != nil { return } diff --git a/core/indexer/indexer.go b/core/indexer/indexer.go index 33f44b764..4c50b49e1 100644 --- a/core/indexer/indexer.go +++ b/core/indexer/indexer.go @@ -15,7 +15,9 @@ import ( "golang.org/x/exp/slices" "github.com/anytypeio/go-anytype-middleware/core/anytype/config" + "github.com/anytypeio/go-anytype-middleware/core/block" "github.com/anytypeio/go-anytype-middleware/core/block/doc" + smartblock2 "github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/editor/template" "github.com/anytypeio/go-anytype-middleware/core/block/source" @@ -130,8 +132,8 @@ type indexer struct { anytype core.Service source source.Service relationService relation.Service + picker block.Picker - doc doc.Service quit chan struct{} mu sync.Mutex btHash Hasher @@ -154,7 +156,7 @@ func (i *indexer) Init(a *app.App) (err error) { i.typeProvider = a.MustComponent(typeprovider.CName).(typeprovider.ObjectTypeProvider) i.source = a.MustComponent(source.CName).(source.Service) i.btHash = a.MustComponent("builtintemplate").(Hasher) - i.doc = a.MustComponent(doc.CName).(doc.Service) + i.picker = app.MustComponent[block.Picker](a) i.fileStore = app.MustComponent[filestore.FileStore](a) i.spaceService = app.MustComponent[space.Service](a) i.quit = make(chan struct{}) @@ -400,7 +402,7 @@ func (i *indexer) reindex(ctx context.Context, flags reindexFlags) (err error) { } if flags.any() { - d, err := i.doc.GetDocInfo(ctx, i.anytype.PredefinedBlocks().Archive) + d, err := i.getObjectInfo(ctx, i.anytype.PredefinedBlocks().Archive) if err != nil { log.Errorf("reindex failed to open archive: %s", err.Error()) } else { @@ -409,7 +411,7 @@ func (i *indexer) reindex(ctx context.Context, flags reindexFlags) (err error) { } } - d, err = i.doc.GetDocInfo(ctx, i.anytype.PredefinedBlocks().Home) + d, err = i.getObjectInfo(ctx, i.anytype.PredefinedBlocks().Home) if err != nil { log.Errorf("reindex failed to open archive: %s", err.Error()) } else { @@ -708,7 +710,7 @@ func (i *indexer) reindexOutdatedThreads() (toReindex, success int, err error) { // } ctx := context.WithValue(context.Background(), metrics.CtxKeyRequest, "reindexOutdatedThreads") - d, err := i.doc.GetDocInfo(ctx, id) + d, err := i.getObjectInfo(ctx, id) if err != nil { continue } @@ -730,7 +732,7 @@ func (i *indexer) reindexDoc(ctx context.Context, id string, indexesWereRemoved return fmt.Errorf("incorrect sb type: %v", err) } - d, err := i.doc.GetDocInfo(ctx, id) + d, err := i.getObjectInfo(ctx, id) if err != nil { log.Errorf("reindexDoc failed to open %s: %s", id, err.Error()) return fmt.Errorf("failed to open doc: %s", err.Error()) @@ -810,6 +812,14 @@ func (i *indexer) reindexIdsIgnoreErr(ctx context.Context, indexRemoved bool, id return } +func (i *indexer) getObjectInfo(ctx context.Context, id string) (info doc.DocInfo, err error) { + err = block.DoWithContext(ctx, i.picker, id, func(sb smartblock2.SmartBlock) error { + info, err = sb.GetDocInfo() + return err + }) + return +} + func (i *indexer) migrateRelations(rels []*model.Relation) { if len(rels) == 0 { return