From 89715bdca7ffd9fb8c11400c3e6dca2726638d69 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 8 Sep 2022 07:50:52 +0200 Subject: [PATCH] Make stuff compile --- service/document/service.go | 2 +- service/sync/requesthandler/requesthandler.go | 7 ++-- service/treecache/service.go | 34 ++++++------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/service/document/service.go b/service/document/service.go index 96084d48..2ae8e239 100644 --- a/service/document/service.go +++ b/service/document/service.go @@ -103,7 +103,7 @@ func (s *service) UpdateDocumentTree(ctx context.Context, id, text string) (err Identity: s.account.Account().Identity, IsSnapshot: false, } - ch, err = docTree.AddContent(ctx, aclTree, signable) + ch, err = docTree.AddContent(ctx, signable) if err != nil { return err } diff --git a/service/sync/requesthandler/requesthandler.go b/service/sync/requesthandler/requesthandler.go index 0b50d156..eeeb0d52 100644 --- a/service/sync/requesthandler/requesthandler.go +++ b/service/sync/requesthandler/requesthandler.go @@ -268,9 +268,11 @@ func (r *requestHandler) createTree( return r.treeCache.Add( ctx, treeId, - treecache.TreePayload{ + storage.TreeStorageCreatePayload{ + TreeId: treeId, Header: header, Changes: response.Changes, + Heads: response.Heads, }) } @@ -283,7 +285,8 @@ func (r *requestHandler) createACLList( return r.treeCache.Add( ctx, treeId, - treecache.ACLListPayload{ + storage.ACLListStorageCreatePayload{ + ListId: treeId, Header: header, Records: req.Records, }) diff --git a/service/treecache/service.go b/service/treecache/service.go index 8b02a120..8a440107 100644 --- a/service/treecache/service.go +++ b/service/treecache/service.go @@ -21,19 +21,9 @@ type ObjFunc = func(obj interface{}) error var log = logger.NewNamed("treecache") -type TreePayload struct { - Header *aclpb.Header - Changes []*aclpb.RawChange -} - -type ACLListPayload struct { - Header *aclpb.Header - Records []*aclpb.RawRecord -} - type Service interface { Do(ctx context.Context, id string, f ObjFunc) error - Add(ctx context.Context, id string, payload interface{}) error + Add(ctx context.Context, id string, payload any) error } type service struct { @@ -59,23 +49,23 @@ func (s *service) Do(ctx context.Context, treeId string, f ObjFunc) error { return f(t) } -func (s *service) Add(ctx context.Context, treeId string, payload interface{}) error { +func (s *service) Add(ctx context.Context, treeId string, payload any) error { switch pl := payload.(type) { - case TreePayload: + case aclstorage.TreeStorageCreatePayload: log. With(zap.String("treeId", treeId), zap.Int("len(changes)", len(pl.Changes))). Debug("adding Tree with changes") - _, err := s.storage.CreateTreeStorage(treeId, pl.Header, pl.Changes) + _, err := s.storage.CreateTreeStorage(payload.(aclstorage.TreeStorageCreatePayload)) if err != nil { return err } - case ACLListPayload: + case aclstorage.ACLListStorageCreatePayload: log. With(zap.String("treeId", treeId), zap.Int("len(changes)", len(pl.Records))). Debug("adding ACLList with records") - _, err := s.storage.CreateACLListStorage(treeId, pl.Header, pl.Records) + _, err := s.storage.CreateACLListStorage(payload.(aclstorage.ACLListStorageCreatePayload)) if err != nil { return err } @@ -123,19 +113,15 @@ func (s *service) loadTree(ctx context.Context, id string) (ocache.Object, error return nil, fmt.Errorf("incorrect type") } log.Info("got header", zap.String("header", header.String())) - var docTree tree.ObjectTree - // TODO: it is a question if we need to use ACLList on the first tree build, because we can think that the tree is already validated + var objTree tree.ObjectTree err = s.Do(ctx, header.AclListId, func(obj interface{}) error { - aclTree := obj.(list.ACLList) - aclTree.RLock() - defer aclTree.RUnlock() - - docTree, err = tree.BuildDocTreeWithIdentity(t.(aclstorage.TreeStorage), s.account.Account(), nil, aclTree) + aclList := obj.(list.ACLList) + objTree, err = tree.BuildObjectTree(t.(aclstorage.TreeStorage), nil, aclList) if err != nil { return err } return nil }) - return docTree, err + return objTree, err }