Skip to content

Commit

Permalink
stores: change Preload to Joins where possible (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Sep 18, 2023
1 parent 6afb988 commit 2faf498
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (s *SQLStore) Contracts(ctx context.Context) ([]api.ContractMetadata, error
var dbContracts []dbContract
err := s.db.
Model(&dbContract{}).
Preload("Host").
Joins("Host").
Find(&dbContracts).
Error
if err != nil {
Expand Down Expand Up @@ -887,7 +887,7 @@ func (s *SQLStore) RenewedContract(ctx context.Context, renewedFrom types.FileCo

err = s.db.
Where(&dbContract{ContractCommon: ContractCommon{RenewedFrom: fileContractID(renewedFrom)}}).
Preload("Host").
Joins("Host").
Take(&contract).
Error
if errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down Expand Up @@ -1778,7 +1778,7 @@ func (s *SQLStore) markPackedSlabUploaded(tx *gorm.DB, slab api.UploadedPackedSl
func contract(tx *gorm.DB, id fileContractID) (contract dbContract, err error) {
err = tx.
Where(&dbContract{ContractCommon: ContractCommon{FCID: id}}).
Preload("Host").
Joins("Host").
Take(&contract).
Error

Expand All @@ -1799,7 +1799,7 @@ func contracts(tx *gorm.DB, ids []types.FileContractID) (dbContracts []dbContrac
err = tx.
Model(&dbContract{}).
Where("fcid IN (?)", fcids).
Preload("Host").
Joins("Host").
Find(&dbContracts).
Error
return
Expand All @@ -1809,7 +1809,7 @@ func contracts(tx *gorm.DB, ids []types.FileContractID) (dbContracts []dbContrac
func contractsForHost(tx *gorm.DB, host dbHost) (contracts []dbContract, err error) {
err = tx.
Where(&dbContract{HostID: host.ID}).
Preload("Host").
Joins("Host").
Find(&contracts).
Error
return
Expand Down

0 comments on commit 2faf498

Please sign in to comment.