Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Preload to Joins where possible #604

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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