From 702cb4a1fe8a0535ca7f6e0825e5539950ebb030 Mon Sep 17 00:00:00 2001 From: kirillston Date: Mon, 3 Jun 2024 15:16:58 +0200 Subject: [PATCH 1/4] GO-3557 Do not erase links in marketplace --- core/indexer/reindex.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/indexer/reindex.go b/core/indexer/reindex.go index 7bbc524f64..aac971978f 100644 --- a/core/indexer/reindex.go +++ b/core/indexer/reindex.go @@ -285,6 +285,7 @@ func (i *indexer) ReindexMarketplaceSpace(space clientspace.Space) error { if err != nil { return err } + flags.eraseLinks = false err = i.removeCommonIndexes(space.Id(), flags) if err != nil { return fmt.Errorf("remove common indexes: %w", err) From 63441ade8c4957ea9d5cf42d1da669fe122d2cba Mon Sep 17 00:00:00 2001 From: kirillston Date: Mon, 3 Jun 2024 16:24:58 +0200 Subject: [PATCH 2/4] GO-3557 Add test --- core/indexer/reindex_test.go | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/core/indexer/reindex_test.go b/core/indexer/reindex_test.go index fed822a8cc..00c8916eb6 100644 --- a/core/indexer/reindex_test.go +++ b/core/indexer/reindex_test.go @@ -60,6 +60,61 @@ func TestReindexMarketplaceSpace(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, details) }) + + t.Run("do not erase links for marketplace", func(t *testing.T) { + // given + indexerFx := NewIndexerFixture(t) + checksums := indexerFx.getLatestChecksums() + checksums.LinksErase = checksums.LinksErase + 1 + err := indexerFx.store.SaveChecksums("spaceId", &checksums) + assert.Nil(t, err) + + virtualSpace := clientspace.NewVirtualSpace("spaceId", clientspace.VirtualSpaceDeps{ + Indexer: indexerFx, + }) + mockCache := mock_objectcache.NewMockCache(t) + smartTest := smarttest.New(addr.MissingObject) + smartTest.SetSpace(virtualSpace) + + smartTest.SetType(coresb.SmartBlockTypePage) + smartTest.SetSpaceId("spaceId") + mockCache.EXPECT().GetObject(context.Background(), addr.MissingObject).Return(editor.NewMissingObject(smartTest), nil) + mockCache.EXPECT().GetObject(context.Background(), addr.AnytypeProfileId).Return(smartTest, nil) + virtualSpace.Cache = mockCache + + favs := []string{"fav1", "fav2"} + trash := []string{"trash1", "trash2"} + err = indexerFx.store.UpdateObjectLinks("home", favs) + require.NoError(t, err) + err = indexerFx.store.UpdateObjectLinks("bin", trash) + require.NoError(t, err) + + homeLinks, err := indexerFx.store.GetOutboundLinksByID("home") + require.Equal(t, favs, homeLinks) + + archiveLinks, err := indexerFx.store.GetOutboundLinksByID("bin") + require.Equal(t, trash, archiveLinks) + + storage := mock_storage.NewMockClientStorage(t) + storage.EXPECT().BindSpaceID(mock.Anything, mock.Anything).Return(nil) + indexerFx.storageService = storage + + // when + err = indexerFx.ReindexMarketplaceSpace(virtualSpace) + assert.NoError(t, err) + + // then + storeChecksums, err := indexerFx.store.GetChecksums(virtualSpace.Id()) + assert.Equal(t, ForceLinksReindexCounter, storeChecksums.LinksErase) + // then + homeLinks, err = indexerFx.store.GetOutboundLinksByID("home") + assert.NoError(t, err) + assert.Equal(t, favs, homeLinks) + + archiveLinks, err = indexerFx.store.GetOutboundLinksByID("bin") + assert.NoError(t, err) + assert.Equal(t, trash, archiveLinks) + }) } func TestReindexDeletedObjects(t *testing.T) { From d1245263ea6820fafdc05088ed46bbf3fcc08a64 Mon Sep 17 00:00:00 2001 From: kirillston Date: Mon, 3 Jun 2024 16:49:43 +0200 Subject: [PATCH 3/4] GO-3557 Do not reindex marketplace space on start --- core/indexer/reindex.go | 1 - core/indexer/reindex_test.go | 55 ------------------- .../internal/marketplacespace/marketplace.go | 7 +-- 3 files changed, 1 insertion(+), 62 deletions(-) diff --git a/core/indexer/reindex.go b/core/indexer/reindex.go index aac971978f..7bbc524f64 100644 --- a/core/indexer/reindex.go +++ b/core/indexer/reindex.go @@ -285,7 +285,6 @@ func (i *indexer) ReindexMarketplaceSpace(space clientspace.Space) error { if err != nil { return err } - flags.eraseLinks = false err = i.removeCommonIndexes(space.Id(), flags) if err != nil { return fmt.Errorf("remove common indexes: %w", err) diff --git a/core/indexer/reindex_test.go b/core/indexer/reindex_test.go index 00c8916eb6..fed822a8cc 100644 --- a/core/indexer/reindex_test.go +++ b/core/indexer/reindex_test.go @@ -60,61 +60,6 @@ func TestReindexMarketplaceSpace(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, details) }) - - t.Run("do not erase links for marketplace", func(t *testing.T) { - // given - indexerFx := NewIndexerFixture(t) - checksums := indexerFx.getLatestChecksums() - checksums.LinksErase = checksums.LinksErase + 1 - err := indexerFx.store.SaveChecksums("spaceId", &checksums) - assert.Nil(t, err) - - virtualSpace := clientspace.NewVirtualSpace("spaceId", clientspace.VirtualSpaceDeps{ - Indexer: indexerFx, - }) - mockCache := mock_objectcache.NewMockCache(t) - smartTest := smarttest.New(addr.MissingObject) - smartTest.SetSpace(virtualSpace) - - smartTest.SetType(coresb.SmartBlockTypePage) - smartTest.SetSpaceId("spaceId") - mockCache.EXPECT().GetObject(context.Background(), addr.MissingObject).Return(editor.NewMissingObject(smartTest), nil) - mockCache.EXPECT().GetObject(context.Background(), addr.AnytypeProfileId).Return(smartTest, nil) - virtualSpace.Cache = mockCache - - favs := []string{"fav1", "fav2"} - trash := []string{"trash1", "trash2"} - err = indexerFx.store.UpdateObjectLinks("home", favs) - require.NoError(t, err) - err = indexerFx.store.UpdateObjectLinks("bin", trash) - require.NoError(t, err) - - homeLinks, err := indexerFx.store.GetOutboundLinksByID("home") - require.Equal(t, favs, homeLinks) - - archiveLinks, err := indexerFx.store.GetOutboundLinksByID("bin") - require.Equal(t, trash, archiveLinks) - - storage := mock_storage.NewMockClientStorage(t) - storage.EXPECT().BindSpaceID(mock.Anything, mock.Anything).Return(nil) - indexerFx.storageService = storage - - // when - err = indexerFx.ReindexMarketplaceSpace(virtualSpace) - assert.NoError(t, err) - - // then - storeChecksums, err := indexerFx.store.GetChecksums(virtualSpace.Id()) - assert.Equal(t, ForceLinksReindexCounter, storeChecksums.LinksErase) - // then - homeLinks, err = indexerFx.store.GetOutboundLinksByID("home") - assert.NoError(t, err) - assert.Equal(t, favs, homeLinks) - - archiveLinks, err = indexerFx.store.GetOutboundLinksByID("bin") - assert.NoError(t, err) - assert.Equal(t, trash, archiveLinks) - }) } func TestReindexDeletedObjects(t *testing.T) { diff --git a/space/internal/marketplacespace/marketplace.go b/space/internal/marketplacespace/marketplace.go index 1898582627..ab6d9db6a3 100644 --- a/space/internal/marketplacespace/marketplace.go +++ b/space/internal/marketplacespace/marketplace.go @@ -30,8 +30,7 @@ type spaceController struct { vs clientspace.Space } -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{ @@ -53,10 +52,6 @@ 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 } From 7566f43736cb34982cad9461548b8f79315b636a Mon Sep 17 00:00:00 2001 From: kirillston Date: Tue, 4 Jun 2024 18:39:14 +0200 Subject: [PATCH 4/4] GO-3557 Move reindex to WaitLoad --- space/internal/marketplacespace/marketplace.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/space/internal/marketplacespace/marketplace.go b/space/internal/marketplacespace/marketplace.go index ab6d9db6a3..bb564891c4 100644 --- a/space/internal/marketplacespace/marketplace.go +++ b/space/internal/marketplacespace/marketplace.go @@ -3,6 +3,7 @@ package marketplacespace import ( "context" "fmt" + "sync" "github.com/anyproto/any-sync/accountservice" "github.com/anyproto/any-sync/app" @@ -21,6 +22,7 @@ func NewSpaceController(a *app.App, personalSpaceId string) spacecontroller.Spac return &spaceController{ app: a, personalSpaceId: personalSpaceId, + indexer: app.MustComponent[dependencies.SpaceIndexer](a), } } @@ -28,6 +30,8 @@ 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) { @@ -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, @@ -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 }