Skip to content

Commit

Permalink
Merge pull request #1815 from anyproto/go-4389-do-not-create-entry-sp…
Browse files Browse the repository at this point in the history
  • Loading branch information
deff7 authored Dec 4, 2024
2 parents 08bb178 + 587a9e4 commit fc7216c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 38 deletions.
3 changes: 1 addition & 2 deletions core/application/account_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ func (s *Service) handleCustomStorageLocation(req *pb.RpcAccountCreateRequest, a
func (s *Service) setAccountAndProfileDetails(ctx context.Context, req *pb.RpcAccountCreateRequest, newAcc *model.Account) error {
spaceService := app.MustComponent[space.Service](s.app)
techSpaceId := spaceService.TechSpaceId()
personalSpaceId := spaceService.PersonalSpaceId()
var err error
newAcc.Info, err = app.MustComponent[account.Service](s.app).GetInfo(ctx)
if err != nil {
return err
}
// TODO: remove it release 8, this is need for client to set "My First Space" as space name
newAcc.Info.AccountSpaceId = personalSpaceId
newAcc.Info.AccountSpaceId = spaceService.FirstCreatedSpaceId()

bs := s.app.MustComponent(block.CName).(*block.Service)
commonDetails := []*model.Detail{
Expand Down
7 changes: 2 additions & 5 deletions core/files/fileobject/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ type objectArchiver interface {
}

func (s *service) deleteMigratedFilesInNonPersonalSpaces(ctx context.Context) error {
personalSpace, err := s.spaceService.GetPersonalSpace(ctx)
if err != nil {
return err
}
personalSpaceId := s.spaceService.PersonalSpaceId()

records, err := s.objectStore.QueryCrossSpace(database.Query{
Filters: []*model.BlockContentDataviewFilter{
Expand All @@ -184,7 +181,7 @@ func (s *service) deleteMigratedFilesInNonPersonalSpaces(ctx context.Context) er
{
RelationKey: bundle.RelationKeySpaceId.String(),
Condition: model.BlockContentDataviewFilter_NotEqual,
Value: pbtypes.String(personalSpace.Id()),
Value: pbtypes.String(personalSpaceId),
},
},
})
Expand Down
1 change: 1 addition & 0 deletions core/files/fileobject/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func newFixture(t *testing.T) *fixture {
fileService := files.New()
spaceService := mock_space.NewMockService(t)
spaceService.EXPECT().GetPersonalSpace(mock.Anything).Return(nil, fmt.Errorf("not needed")).Maybe()
spaceService.EXPECT().PersonalSpaceId().Return("personalSpaceId").Maybe()
spaceIdResolver := mock_idresolver.NewMockResolver(t)

svc := New(testResolveRetryDelay, testResolveRetryDelay)
Expand Down
2 changes: 1 addition & 1 deletion docs/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -28081,7 +28081,7 @@ Contains basic information about a user account
| marketplaceWorkspaceId | [string](#string) | | marketplace workspace id |
| workspaceObjectId | [string](#string) | | workspace object id. used for space-level chat |
| deviceId | [string](#string) | | |
| accountSpaceId | [string](#string) | | |
| accountSpaceId | [string](#string) | | the first created private space. It's filled only when account is created |
| widgetsId | [string](#string) | | |
| spaceViewId | [string](#string) | | |
| techSpaceId | [string](#string) | | |
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/pb/model/protos/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ message Account {
string workspaceObjectId = 15; // workspace object id. used for space-level chat

string deviceId = 8;
string accountSpaceId = 9;
string accountSpaceId = 9; // the first created private space. It's filled only when account is created
string widgetsId = 10;
string spaceViewId = 13;
string techSpaceId = 14;
Expand Down
26 changes: 0 additions & 26 deletions space/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ import (
"github.com/anyproto/anytype-heart/space/internal/spaceprocess/loader"
)

func (s *service) createPersonalSpace(ctx context.Context) (err error) {
s.mu.Lock()
wait := make(chan struct{})
s.waiting[s.personalSpaceId] = controllerWaiter{
wait: wait,
}
s.mu.Unlock()
ctrl, err := s.factory.CreatePersonalSpace(ctx, s.accountMetadataPayload)
if err != nil {
return
}
_, err = ctrl.Current().(loader.LoadWaiter).WaitLoad(ctx)
s.mu.Lock()
defer s.mu.Unlock()
close(wait)
if err != nil {
s.waiting[s.personalSpaceId] = controllerWaiter{
wait: wait,
err: err,
}
return
}
s.spaceControllers[s.personalSpaceId] = ctrl
return
}

func (s *service) create(ctx context.Context) (sp clientspace.Space, err error) {
coreSpace, err := s.spaceCore.Create(ctx, s.repKey, s.AccountMetadataPayload())
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions space/mock_space/mock_Service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion space/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Service interface {
Delete(ctx context.Context, id string) (err error)
TechSpaceId() string
PersonalSpaceId() string
FirstCreatedSpaceId() string
TechSpace() *clientspace.TechSpace
GetPersonalSpace(ctx context.Context) (space clientspace.Space, err error)
GetTechSpace(ctx context.Context) (space clientspace.Space, err error)
Expand Down Expand Up @@ -107,6 +108,8 @@ type service struct {
ctx context.Context // use ctx for the long operations within the lifecycle of the service, excluding Run
ctxCancel context.CancelFunc
isClosing atomic.Bool

firstCreatedSpaceId string
}

func (s *service) Delete(ctx context.Context, id string) (err error) {
Expand Down Expand Up @@ -276,7 +279,7 @@ func (s *service) createAccount(ctx context.Context) (err error) {
if err != nil {
return fmt.Errorf("init tech space: %w", err)
}
err = s.createPersonalSpace(ctx)
firstSpace, err := s.create(ctx)
if err != nil {
if errors.Is(err, spacesyncproto.ErrSpaceMissing) || errors.Is(err, treechangeproto.ErrGetTree) {
err = ErrSpaceNotExists
Expand All @@ -288,6 +291,9 @@ func (s *service) createAccount(ctx context.Context) (err error) {
}
return fmt.Errorf("init personal space: %w", err)
}

s.firstCreatedSpaceId = firstSpace.Id()

s.techSpace.WakeUpViews()
// only persist networkId after successful space init
err = s.config.PersistAccountNetworkId()
Expand Down Expand Up @@ -481,6 +487,10 @@ func (s *service) PersonalSpaceId() string {
return s.personalSpaceId
}

func (s *service) FirstCreatedSpaceId() string {
return s.firstCreatedSpaceId
}

func (s *service) getTechSpace(ctx context.Context) (*clientspace.TechSpace, error) {
select {
case <-s.techSpaceReady:
Expand Down
9 changes: 7 additions & 2 deletions space/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/commonspace/mock_commonspace"
"github.com/anyproto/any-sync/commonspace/object/accountdata"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/coordinator/coordinatorclient/mock_coordinatorclient"
Expand Down Expand Up @@ -46,7 +47,6 @@ const (
testPersonalSpaceID = "personal.12345"
)

// TODO Revive tests
func TestService_Init(t *testing.T) {
t.Run("tech space getter", func(t *testing.T) {
serv := New().(*service)
Expand Down Expand Up @@ -403,8 +403,13 @@ func (fx *fixture) expectRun(t *testing.T, expectOldAccount func(t *testing.T, f
if expectOldAccount == nil {
fx.factory.EXPECT().CreateAndSetTechSpace(mock.Anything).Return(&clientspace.TechSpace{TechSpace: ts}, nil)
prCtrl := mock_spacecontroller.NewMockSpaceController(t)
fx.factory.EXPECT().CreatePersonalSpace(mock.Anything, mock.Anything).Return(prCtrl, nil)
prCtrl.EXPECT().SpaceId().Return(fx.spaceId)
commonSpace := mock_commonspace.NewMockSpace(fx.ctrl)
commonSpace.EXPECT().Id().Return(fx.spaceId).AnyTimes()
fx.spaceCore.EXPECT().Create(mock.Anything, mock.Anything, mock.Anything).Return(&spacecore.AnySpace{Space: commonSpace}, nil)
fx.factory.EXPECT().CreateShareableSpace(mock.Anything, mock.Anything).Return(prCtrl, nil)
lw := lwMock{clientSpace}
clientSpace.EXPECT().Id().Return(fx.spaceId)
prCtrl.EXPECT().Current().Return(lw)
prCtrl.EXPECT().Close(mock.Anything).Return(nil)
ts.EXPECT().WakeUpViews()
Expand Down

0 comments on commit fc7216c

Please sign in to comment.