1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

GO-501: Get object info directly without doc service

This commit is contained in:
Sergey 2023-04-25 18:17:59 +02:00 committed by Mikhail Iudin
parent f6b71b8300
commit 2f68506359
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
4 changed files with 20 additions and 33 deletions

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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