Add client space

This commit is contained in:
mcrakhman 2022-11-07 15:53:27 +01:00 committed by Mikhail Iudin
parent 4881c052aa
commit 7167b71a90
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
2 changed files with 38 additions and 3 deletions

View File

@ -41,9 +41,7 @@ func (s *service) Init(a *app.App) (err error) {
s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service)
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
s.spaceCache = ocache.New(
func(ctx context.Context, id string) (value ocache.Object, err error) {
return s.commonSpace.NewSpace(ctx, id)
},
s.loadSpace,
ocache.WithLogger(log.Sugar()),
ocache.WithGCPeriod(time.Minute),
ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second),
@ -97,6 +95,21 @@ func (s *service) AddSpace(ctx context.Context, description commonspace.SpaceDes
return s.commonSpace.AddSpace(ctx, description)
}
func (s *service) loadSpace(ctx context.Context, id string) (value ocache.Object, err error) {
cc, err := s.commonSpace.NewSpace(ctx, id)
if err != nil {
return
}
ns, err := newClientSpace(cc)
if err != nil {
return
}
if err = ns.Init(ctx); err != nil {
return
}
return ns, nil
}
func (s *service) Close(ctx context.Context) (err error) {
return s.spaceCache.Close()
}

View File

@ -0,0 +1,22 @@
package clientspace
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
)
func newClientSpace(cc commonspace.Space) (commonspace.Space, error) {
return &clientSpace{cc}, nil
}
type clientSpace struct {
commonspace.Space
}
func (s *clientSpace) Init(ctx context.Context) (err error) {
return s.Space.Init(ctx)
}
func (s *clientSpace) Close() (err error) {
return s.Space.Close()
}