1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Merge pull request #420 from anyproto/GO-5311-root-without-parse

GO-5311: Fix parser issue in tree, add comments
This commit is contained in:
Mikhail Rakhmanov 2025-03-18 20:17:45 +01:00 committed by GitHub
commit ae5254c40e
Signed by: github
GPG key ID: B5690EEEBB952194

View file

@ -162,7 +162,7 @@ func NewStorage(ctx context.Context, id string, headStorage headstorage.HeadStor
st.changesColl = changesColl
st.arena = &anyenc.Arena{}
st.parser = &anyenc.Parser{}
st.root, err = st.Get(ctx, st.id)
st.root, err = st.getWithoutParser(ctx, st.id)
if err != nil {
if errors.Is(err, anystore.ErrDocNotFound) {
return nil, treestorage.ErrUnknownTreeId
@ -193,6 +193,7 @@ func (s *storage) Has(ctx context.Context, id string) (bool, error) {
}
func (s *storage) GetAfterOrder(ctx context.Context, orderId string, storageIter StorageIterator) error {
// this method can be called without having a lock on a tree, so don't reuse any non-thread-safe parts
filter := query.And{
query.Key{Path: []string{OrderKey}, Filter: query.NewComp(query.CompOpGte, orderId)},
query.Key{Path: []string{TreeKey}, Filter: query.NewComp(query.CompOpEq, s.id)},
@ -311,6 +312,15 @@ func (s *storage) CommonSnapshot(ctx context.Context) (string, error) {
return entry.CommonSnapshot, nil
}
func (s *storage) getWithoutParser(ctx context.Context, id string) (StorageChange, error) {
// root will be reused outside the lock, so we shouldn't use parser for it
doc, err := s.changesColl.FindId(ctx, id)
if err != nil {
return StorageChange{}, err
}
return s.changeFromDoc(doc), nil
}
func (s *storage) Get(ctx context.Context, id string) (StorageChange, error) {
doc, err := s.changesColl.FindIdWithParser(ctx, s.parser, id)
if err != nil {