diff --git a/stores/metadata.go b/stores/metadata.go index 618ab41d9..901c0f73b 100644 --- a/stores/metadata.go +++ b/stores/metadata.go @@ -1845,13 +1845,19 @@ func (ss *SQLStore) UpdateSlab(ctx context.Context, s object.Slab, contractSet s // Update slab. return ss.retryTransaction(func(tx *gorm.DB) (err error) { - // fetch contract set - var cs dbContractSet - if err := tx.Take(&cs, "name = ?", contractSet).Error; err != nil { + // update slab + if err := tx.Model(&dbSlab{}). + Where("key", key). + Updates(map[string]interface{}{ + "db_contract_set_id": gorm.Expr("(SELECT id FROM contract_sets WHERE name = ?)", contractSet), + "health_valid_until": time.Now().Unix(), + "health": 1, + }). + Error; err != nil { return err } - // find all contracts of that shard + // find all used contracts contracts, err := fetchUsedContracts(tx, usedContracts) if err != nil { return err @@ -1885,18 +1891,6 @@ func (ss *SQLStore) UpdateSlab(ctx context.Context, s object.Slab, contractSet s } } - // update fields - if err := tx.Model(&slab). - Where(&slab). - Updates(map[string]interface{}{ - "db_contract_set_id": cs.ID, - "health_valid_until": time.Now().Unix(), - "health": 1, - }). - Error; err != nil { - return err - } - // prepare sectors to update sectors := make([]dbSector, len(s.Shards)) for i := range s.Shards {