Skip to content

Commit

Permalink
GO-3557 Move reindex to WaitLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillSto committed Jun 4, 2024
1 parent d124526 commit 7566f43
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions space/internal/marketplacespace/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package marketplacespace
import (
"context"
"fmt"
"sync"

"github.com/anyproto/any-sync/accountservice"
"github.com/anyproto/any-sync/app"
Expand All @@ -21,13 +22,16 @@ func NewSpaceController(a *app.App, personalSpaceId string) spacecontroller.Spac
return &spaceController{
app: a,
personalSpaceId: personalSpaceId,
indexer: app.MustComponent[dependencies.SpaceIndexer](a),
}
}

type spaceController struct {
app *app.App
personalSpaceId string
vs clientspace.Space
reindexOnce sync.Once
indexer dependencies.SpaceIndexer
}

func (s *spaceController) Start(context.Context) (err error) {
Expand All @@ -37,7 +41,7 @@ func (s *spaceController) Start(context.Context) (err error) {
ObjectFactory: app.MustComponent[objectcache.ObjectFactory](s.app),
AccountService: app.MustComponent[accountservice.Service](s.app),
PersonalSpaceId: s.personalSpaceId,
Indexer: app.MustComponent[dependencies.SpaceIndexer](s.app),
Indexer: s.indexer,
Installer: app.MustComponent[dependencies.BundledObjectsInstaller](s.app),
TypePrefix: addr.BundledObjectTypeURLPrefix,
RelationPrefix: addr.BundledRelationURLPrefix,
Expand All @@ -59,7 +63,14 @@ func (s *spaceController) Mode() mode.Mode {
return mode.ModeLoading
}

func (s *spaceController) WaitLoad(ctx context.Context) (sp clientspace.Space, err error) {
func (s *spaceController) WaitLoad(context.Context) (sp clientspace.Space, err error) {
s.reindexOnce.Do(func() {
// TODO: GO-3557 Need to confirm moving ReindexMarketplaceSpace from Start to WaitLoad with mcrakhman
err = s.indexer.ReindexMarketplaceSpace(s.vs)
})
if err != nil {
return nil, err
}
return s.vs, nil
}

Expand Down

0 comments on commit 7566f43

Please sign in to comment.