Fix add text bug

This commit is contained in:
mcrakhman 2022-10-20 19:08:43 +02:00 committed by Mikhail Iudin
parent f213ec7efe
commit 40d5d832fb
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
2 changed files with 7 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace" "github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document/textdocument" "github.com/anytypeio/go-anytype-infrastructure-experiments/client/document/textdocument"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
@ -24,6 +25,7 @@ const spaceKey ctxKey = 0
type treeCache struct { type treeCache struct {
gcttl int gcttl int
cache ocache.OCache cache ocache.OCache
account account.Service
clientService clientspace.Service clientService clientspace.Service
} }
@ -65,6 +67,7 @@ func (c *treeCache) Close(ctx context.Context) (err error) {
func (c *treeCache) Init(a *app.App) (err error) { func (c *treeCache) Init(a *app.App) (err error) {
c.clientService = a.MustComponent(clientspace.CName).(clientspace.Service) c.clientService = a.MustComponent(clientspace.CName).(clientspace.Service)
c.account = a.MustComponent(account.CName).(account.Service)
c.cache = ocache.New( c.cache = ocache.New(
func(ctx context.Context, id string) (value ocache.Object, err error) { func(ctx context.Context, id string) (value ocache.Object, err error) {
spaceId := ctx.Value(spaceKey).(string) spaceId := ctx.Value(spaceKey).(string)
@ -72,7 +75,7 @@ func (c *treeCache) Init(a *app.App) (err error) {
if err != nil { if err != nil {
return return
} }
return textdocument.NewTextDocument(context.Background(), space, id, &updateListener{}) return textdocument.NewTextDocument(context.Background(), space, id, &updateListener{}, c.account)
}, },
ocache.WithLogger(log.Sugar()), ocache.WithLogger(log.Sugar()),
ocache.WithGCPeriod(time.Minute), ocache.WithGCPeriod(time.Minute),

View File

@ -40,16 +40,18 @@ func CreateTextDocument(
return &textDocument{ return &textDocument{
objTree: t, objTree: t,
account: account,
}, nil }, nil
} }
func NewTextDocument(ctx context.Context, space commonspace.Space, id string, listener updatelistener.UpdateListener) (doc TextDocument, err error) { func NewTextDocument(ctx context.Context, space commonspace.Space, id string, listener updatelistener.UpdateListener, account account.Service) (doc TextDocument, err error) {
t, err := space.BuildTree(ctx, id, listener) t, err := space.BuildTree(ctx, id, listener)
if err != nil { if err != nil {
return return
} }
return &textDocument{ return &textDocument{
objTree: t, objTree: t,
account: account,
}, nil }, nil
} }