mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 02:13:41 +09:00
Update to latest any-sync with delayed load
This commit is contained in:
parent
ece3108695
commit
8ea7ccaad0
7 changed files with 32 additions and 9 deletions
|
@ -30,7 +30,9 @@ type ctxKey int
|
|||
var errAppIsNotRunning = errors.New("app is not running")
|
||||
|
||||
const (
|
||||
optsKey ctxKey = iota
|
||||
optsKey ctxKey = iota
|
||||
derivedObjectLoadTimeout = time.Minute * 30
|
||||
objectLoadTimeout = time.Minute * 3
|
||||
)
|
||||
|
||||
type treeCreateCache struct {
|
||||
|
@ -124,6 +126,11 @@ func (s *Service) GetAccountTree(ctx context.Context, id string) (tr objecttree.
|
|||
}
|
||||
|
||||
func (s *Service) GetAccountObject(ctx context.Context, id string) (sb smartblock.SmartBlock, err error) {
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(ctx, objectLoadTimeout)
|
||||
defer cancel()
|
||||
}
|
||||
return s.GetObject(ctx, s.clientService.AccountId(), id)
|
||||
}
|
||||
|
||||
|
@ -337,7 +344,8 @@ func (s *Service) getDerivedObject(
|
|||
id = payload.RootRawChange.Id
|
||||
)
|
||||
// timing out when getting objects from remote
|
||||
ctx, cancel = context.WithTimeout(ctx, time.Minute)
|
||||
// here we set very long timeout, because we must load these documents
|
||||
ctx, cancel = context.WithTimeout(ctx, derivedObjectLoadTimeout)
|
||||
ctx = context.WithValue(ctx,
|
||||
optsKey,
|
||||
cacheOpts{
|
||||
|
|
|
@ -97,7 +97,7 @@ func (f *ObjectFactory) Name() (name string) {
|
|||
}
|
||||
|
||||
func (f *ObjectFactory) InitObject(id string, initCtx *smartblock.InitContext) (sb smartblock.SmartBlock, err error) {
|
||||
sc, err := f.sourceService.NewSource(id, initCtx.SpaceID, initCtx.BuildOpts)
|
||||
sc, err := f.sourceService.NewSource(initCtx.Ctx, id, initCtx.SpaceID, initCtx.BuildOpts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func New() Service {
|
|||
}
|
||||
|
||||
type Service interface {
|
||||
NewSource(id string, spaceID string, buildOptions BuildOptions) (source Source, err error)
|
||||
NewSource(ctx context.Context, id string, spaceID string, buildOptions BuildOptions) (source Source, err error)
|
||||
RegisterStaticSource(id string, s Source)
|
||||
NewStaticSource(id string, sbType model.SmartBlockType, doc *state.State, pushChange func(p PushChangeParams) (string, error)) SourceWithType
|
||||
RemoveStaticSource(id string)
|
||||
|
@ -81,7 +81,7 @@ func (b *BuildOptions) BuildTreeOpts() commonspace.BuildTreeOpts {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *service) NewSource(id string, spaceID string, buildOptions BuildOptions) (source Source, err error) {
|
||||
func (s *service) NewSource(ctx context.Context, id string, spaceID string, buildOptions BuildOptions) (source Source, err error) {
|
||||
if id == addr.AnytypeProfileId {
|
||||
return NewAnytypeProfile(id), nil
|
||||
}
|
||||
|
@ -107,7 +107,6 @@ func (s *service) NewSource(id string, spaceID string, buildOptions BuildOptions
|
|||
return staticSrc, nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
spc, err := s.spaceService.GetSpace(ctx, spaceID)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -357,6 +357,12 @@ func (i *indexer) reindex(ctx context.Context, flags reindexFlags) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// starting sync of all other objects later, because we don't want to have problems with loading of derived objects
|
||||
// due to parallel load which can overload the stream
|
||||
err = i.spaceService.StartSync(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if flags.any() {
|
||||
d, err := i.getObjectInfo(ctx, i.anytype.PredefinedBlocks().Archive)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/PuerkitoBio/goquery v1.8.1
|
||||
github.com/VividCortex/ewma v1.2.0
|
||||
github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786
|
||||
github.com/anyproto/any-sync v0.1.1
|
||||
github.com/anyproto/any-sync v0.1.2-0.20230524194759-a5e2bea04c2b
|
||||
github.com/anyproto/go-naturaldate/v2 v2.0.2-0.20230524105841-9829cfd13438
|
||||
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
|
||||
github.com/blevesearch/bleve/v2 v2.3.6
|
||||
|
|
4
go.sum
4
go.sum
|
@ -44,8 +44,8 @@ github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxB
|
|||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/anyproto/any-sync v0.1.1 h1:fZ6SfiSf4tX3Ab+76cZAxAm/3uY60lnndyBgeqenT8w=
|
||||
github.com/anyproto/any-sync v0.1.1/go.mod h1:N56AZy/MmqabgNPWc4+Ta6Tbkk0Ob7sYLfNpzK4Hv7M=
|
||||
github.com/anyproto/any-sync v0.1.2-0.20230524194759-a5e2bea04c2b h1:qpD1wy54HS9G46z3R3TX4xjEVhNU0+jgfEKgxjbmwcM=
|
||||
github.com/anyproto/any-sync v0.1.2-0.20230524194759-a5e2bea04c2b/go.mod h1:N56AZy/MmqabgNPWc4+Ta6Tbkk0Ob7sYLfNpzK4Hv7M=
|
||||
github.com/anyproto/go-chash v0.1.0 h1:I9meTPjXFRfXZHRJzjOHC/XF7Q5vzysKkiT/grsogXY=
|
||||
github.com/anyproto/go-chash v0.1.0/go.mod h1:0UjNQi3PDazP0fINpFYu6VKhuna+W/V+1vpXHAfNgLY=
|
||||
github.com/anyproto/go-ds-badger3 v0.3.1-0.20230524095230-434cf6346d9b h1:SMizb43hfILk2bpMgpTd30n6yQQdxW0ZbDti0wqfsBw=
|
||||
|
|
|
@ -61,6 +61,7 @@ type Service interface {
|
|||
DeleteSpace(ctx context.Context, spaceID string, revert bool) (payload StatusPayload, err error)
|
||||
DeleteAccount(ctx context.Context, revert bool) (payload StatusPayload, err error)
|
||||
StreamPool() streampool.StreamPool
|
||||
StartSync(ctx context.Context) (err error)
|
||||
app.ComponentRunnable
|
||||
}
|
||||
|
||||
|
@ -147,6 +148,15 @@ func (s *service) Run(ctx context.Context) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *service) StartSync(ctx context.Context) (err error) {
|
||||
sp, err := s.AccountSpace(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sp.HeadSync().Run()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *service) DeriveSpace(ctx context.Context, payload commonspace.SpaceDerivePayload) (container commonspace.Space, err error) {
|
||||
id, err := s.commonSpace.DeriveSpace(ctx, payload)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue