1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

GO-3663: A bunch of fixes

This commit is contained in:
Sergey 2024-07-19 10:22:58 +02:00
parent c7963fa4ae
commit e583fc4aad
No known key found for this signature in database
GPG key ID: 3B6BEF79160221C6
11 changed files with 36 additions and 21 deletions

View file

@ -72,7 +72,7 @@ test-integration:
test-race:
@echo 'Running tests with race-detector...'
@ANYTYPE_LOG_NOGELF=1 go test -race github.com/anyproto/anytype-heart/...
@ANYTYPE_LOG_NOGELF=1 go test -count=1 -race github.com/anyproto/anytype-heart/...
test-deps:
@echo 'Generating test mocks...'

View file

@ -2,8 +2,10 @@ package dataview
import (
"context"
"errors"
"fmt"
anystore "github.com/anyproto/any-store"
"github.com/globalsign/mgo/bson"
"github.com/google/uuid"
@ -21,7 +23,6 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
"github.com/anyproto/anytype-heart/pkg/lib/logging"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/util/badgerhelper"
"github.com/anyproto/anytype-heart/util/pbtypes"
"github.com/anyproto/anytype-heart/util/slice"
)
@ -428,7 +429,7 @@ func (d *sdataview) checkDVBlocks(info smartblock.ApplyInfo) (err error) {
func (d *sdataview) injectActiveViews(info smartblock.ApplyInfo) (err error) {
s := info.State
views, err := d.objectStore.GetActiveViews(d.Id())
if badgerhelper.IsNotFound(err) {
if errors.Is(err, anystore.ErrDocNotFound) {
return nil
}
if err != nil {

View file

@ -5,7 +5,7 @@ import (
"fmt"
"testing"
"github.com/dgraph-io/badger/v4"
anystore "github.com/anyproto/any-store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@ -128,7 +128,7 @@ func TestInjectActiveView(t *testing.T) {
fx := newFixture(t)
fx.store.EXPECT().GetActiveViews(mock.Anything).RunAndReturn(func(id string) (map[string]string, error) {
assert.Equal(t, objId, id)
return nil, badger.ErrKeyNotFound
return nil, anystore.ErrDocNotFound
})
info := getInfo()

View file

@ -1,6 +1,9 @@
package filesync
import (
"encoding/json"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
@ -91,6 +94,12 @@ func TestSpaceUsageUpdate(t *testing.T) {
makeLimitUpdatedEvent(limit * 10),
}
assert.Equal(t, wantEvents, fx.events)
if !assert.Equal(t, wantEvents, fx.events) {
m := json.NewEncoder(os.Stdout)
m.SetIndent("", " ")
m.Encode(wantEvents)
fmt.Println("---")
m.Encode(fx.events)
}
})
}

View file

@ -23,6 +23,7 @@ import (
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
coresb "github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/datastore"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/filestore"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/ftsearch"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
@ -53,7 +54,11 @@ func NewIndexerFixture(t *testing.T) *IndexerFixture {
fileStore := filestore.New()
ds, err := datastore.NewInMemory()
require.NoError(t, err)
testApp := &app.App{}
testApp.Register(ds)
testApp.Register(walletService)
testApp.Register(objectStore.FTSearch())

View file

@ -7,8 +7,8 @@ import (
"strings"
"time"
anystore "github.com/anyproto/any-store"
"github.com/anyproto/any-sync/util/slice"
"github.com/dgraph-io/badger/v4"
"github.com/globalsign/mgo/bson"
"github.com/gogo/protobuf/types"
"go.uber.org/zap"
@ -50,12 +50,12 @@ const (
func (i *indexer) buildFlags(spaceID string) (reindexFlags, error) {
checksums, err := i.store.GetChecksums(spaceID)
if err != nil && !errors.Is(err, badger.ErrKeyNotFound) {
if err != nil && !errors.Is(err, anystore.ErrDocNotFound) {
return reindexFlags{}, err
}
if checksums == nil {
checksums, err = i.store.GetGlobalChecksums()
if err != nil && !errors.Is(err, badger.ErrKeyNotFound) {
if err != nil && !errors.Is(err, anystore.ErrDocNotFound) {
return reindexFlags{}, err
}

View file

@ -51,6 +51,7 @@ type MetricsService interface {
}
type service struct {
startOnce *sync.Once
lock sync.RWMutex
appVersion string
startVersion string
@ -72,6 +73,7 @@ func NewService() MetricsService {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
return &service{
startOnce: &sync.Once{},
clients: [1]*client{
inhouse: {
aggregatableMap: make(map[string]SamplableEvent),
@ -84,9 +86,11 @@ func NewService() MetricsService {
}
func (s *service) InitWithKeys(inHouseKey string) {
s.lock.Lock()
defer s.lock.Unlock()
s.clients[inhouse].telemetry = anymetry.New(inHouseEndpoint, inHouseKey, true)
s.startOnce.Do(func() {
s.lock.Lock()
defer s.lock.Unlock()
s.clients[inhouse].telemetry = anymetry.New(inHouseEndpoint, inHouseKey, true)
})
}
func (s *service) SetDeviceId(t string) {

View file

@ -2,10 +2,8 @@ package objectstore
import (
"encoding/json"
"errors"
"fmt"
anystore "github.com/anyproto/any-store"
"github.com/anyproto/any-sync/coordinator/coordinatorproto"
"github.com/valyala/fastjson"
)
@ -43,9 +41,6 @@ func (s *dsObjectStore) SaveAccountStatus(status *coordinatorproto.SpaceStatusPa
func (s *dsObjectStore) GetAccountStatus() (*coordinatorproto.SpaceStatusPayload, error) {
doc, err := s.system.FindId(s.componentCtx, accountStatusKey)
if errors.Is(err, anystore.ErrDocNotFound) {
return &coordinatorproto.SpaceStatusPayload{}, nil
}
if err != nil {
return nil, fmt.Errorf("find account status: %w", err)
}

View file

@ -40,6 +40,9 @@ func (s *dsObjectStore) SetActiveView(objectId, blockId, viewId string) error {
// GetActiveViews returns a map of activeViews by block ids
func (s *dsObjectStore) GetActiveViews(objectId string) (map[string]string, error) {
doc, err := s.activeViews.FindId(s.componentCtx, objectId)
if errors.Is(err, anystore.ErrDocNotFound) {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("get active view: %w", err)
}

View file

@ -75,9 +75,6 @@ func (s *dsObjectStore) RemoveIDsFromFullTextQueue(ids []string) error {
func (s *dsObjectStore) GetChecksums(spaceID string) (*model.ObjectStoreChecksums, error) {
doc, err := s.indexerChecksums.FindId(s.componentCtx, spaceID)
if errors.Is(err, anystore.ErrDocNotFound) {
return &model.ObjectStoreChecksums{}, nil
}
if err != nil {
return nil, fmt.Errorf("get checksums: %w", err)
}

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
anystore "github.com/anyproto/any-store"
"github.com/dgraph-io/badger/v4"
"github.com/gogo/protobuf/proto"
)
@ -99,7 +100,7 @@ func GetValueTxn[T any](txn *badger.Txn, key []byte, unmarshaler func([]byte) (T
}
func IsNotFound(err error) bool {
return errors.Is(err, badger.ErrKeyNotFound)
return errors.Is(err, badger.ErrKeyNotFound) || errors.Is(err, anystore.ErrDocNotFound)
}
func ViewTxnWithResult[T any](db *badger.DB, f func(txn *badger.Txn) (T, error)) (T, error) {