Skip to content

Commit

Permalink
stores: change UpdateSlab to update slab first
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Feb 28, 2024
1 parent 47939ba commit 5d37ac9
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5d37ac9

Please sign in to comment.