Skip to content

Commit

Permalink
Merge pull request #1291 from anyproto/go-3557-crash-on-marketplace-r…
Browse files Browse the repository at this point in the history
…eindex

GO-3557 Reindex marketplace on space loading
  • Loading branch information
KirillSto authored Jun 5, 2024
2 parents c32d8fe + 7566f43 commit 8d994cf
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 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,24 +22,26 @@ 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(ctx context.Context) (err error) {
indexer := app.MustComponent[dependencies.SpaceIndexer](s.app)
func (s *spaceController) Start(context.Context) (err error) {
s.vs = clientspace.NewVirtualSpace(
addr.AnytypeMarketplaceWorkspace,
clientspace.VirtualSpaceDeps{
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 @@ -53,18 +56,21 @@ func (s *spaceController) Start(ctx context.Context) (err error) {
if err != nil {
return fmt.Errorf("register builtin templates: %w", err)
}
err = indexer.ReindexMarketplaceSpace(s.vs)
if err != nil {
return fmt.Errorf("reindex marketplace space: %w", err)
}
return err
}

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 8d994cf

Please sign in to comment.