Add client space
This commit is contained in:
parent
4881c052aa
commit
7167b71a90
@ -41,9 +41,7 @@ func (s *service) Init(a *app.App) (err error) {
|
|||||||
s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service)
|
s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service)
|
||||||
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
|
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
|
||||||
s.spaceCache = ocache.New(
|
s.spaceCache = ocache.New(
|
||||||
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
s.loadSpace,
|
||||||
return s.commonSpace.NewSpace(ctx, id)
|
|
||||||
},
|
|
||||||
ocache.WithLogger(log.Sugar()),
|
ocache.WithLogger(log.Sugar()),
|
||||||
ocache.WithGCPeriod(time.Minute),
|
ocache.WithGCPeriod(time.Minute),
|
||||||
ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second),
|
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)
|
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) {
|
func (s *service) Close(ctx context.Context) (err error) {
|
||||||
return s.spaceCache.Close()
|
return s.spaceCache.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
22
client/clientspace/space.go
Normal file
22
client/clientspace/space.go
Normal 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()
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user