diff --git a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go index 099be443d..6d546638e 100644 --- a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go +++ b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go @@ -96,11 +96,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock) { ), ) - mock.ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "reference_objects" WHERE`)). - WillReturnRows( - sqlmock.NewRows([]string{"count"}).AddRow(1000), - ) - mock.ExpectCommit() } diff --git a/code/go/0chain.net/blobbercore/filestore/state.go b/code/go/0chain.net/blobbercore/filestore/state.go index 69e7664ea..b7c683b3b 100644 --- a/code/go/0chain.net/blobbercore/filestore/state.go +++ b/code/go/0chain.net/blobbercore/filestore/state.go @@ -65,6 +65,9 @@ func (fs *FileStore) initMap() error { allocsMap := make(map[string]*allocation) for _, dbAlloc := range dbAllocations { + if dbAlloc.CleanedUp || dbAlloc.Finalized { + continue + } a := allocation{ allocatedSize: uint64(dbAlloc.BlobberSize), mu: &sync.Mutex{}, @@ -72,12 +75,7 @@ func (fs *FileStore) initMap() error { } allocsMap[dbAlloc.ID] = &a - if dbAlloc.StorageVersion == 0 { - err := getStorageDetails(ctx, &a, dbAlloc.ID) - if err != nil { - return err - } - } else { + if dbAlloc.StorageVersion != 0 { a.filesNumber = uint64(dbAlloc.NumObjects) } a.filesSize = uint64(dbAlloc.BlobberSizeUsed) @@ -156,22 +154,6 @@ func (ref) TableName() string { return "reference_objects" } -func getStorageDetails(ctx context.Context, a *allocation, ID string) error { - db := datastore.GetStore().GetTransaction(ctx) - r := map[string]interface{}{ - "allocation_id": ID, - "type": "f", - } - var totalFiles int64 - if err := db.Model(&ref{}).Where(r).Count(&totalFiles).Error; err != nil { - return err - } - a.mu.Lock() - defer a.mu.Unlock() - a.filesNumber = uint64(totalFiles) - return nil -} - // UpdateAllocationMetaData only updates if allocation size has changed or new allocation is allocated. Must use allocationID. // Use of allocation Tx might leak memory. allocation size must be of int64 type otherwise it won't be updated func (fs *FileStore) UpdateAllocationMetaData(m map[string]interface{}) error { diff --git a/code/go/0chain.net/blobbercore/filestore/store_test.go b/code/go/0chain.net/blobbercore/filestore/store_test.go index 235b8ca22..11edbd7f8 100644 --- a/code/go/0chain.net/blobbercore/filestore/store_test.go +++ b/code/go/0chain.net/blobbercore/filestore/store_test.go @@ -134,13 +134,11 @@ func TestStore(t *testing.T) { require.NotNil(t, alloc) require.Equal(t, ip.allocatedSize, alloc.allocatedSize) - require.Equal(t, ip.totalRefs, alloc.filesNumber) require.Equal(t, ip.usedSize, alloc.filesSize) } func setupMockForFileManagerInit(mock sqlmock.Sqlmock, ip initParams) { - aa := sqlmock.AnyArg() mock.ExpectBegin() mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "allocations"`)). @@ -153,12 +151,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock, ip initParams) { ), ) - mock.ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "reference_objects" WHERE`)). - WithArgs(aa, aa). - WillReturnRows( - sqlmock.NewRows([]string{"count"}).AddRow(ip.totalRefs), - ) - mock.ExpectCommit() }