Skip to content

Commit

Permalink
lxd/storage_volumes: optimize database calls on storagePoolVolumesGet
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Apr 18, 2024
1 parent f90ec17 commit f475e94
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lxd/storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,29 +688,21 @@ func storagePoolVolumesGet(d *Daemon, r *http.Request) response.Response {
}

if allPools {
poolNames, err := tx.GetStoragePoolNames(ctx)
dbVolumes, err = tx.GetStoragePoolVolumes(ctx, memberSpecific, filters...)
if err != nil {
return fmt.Errorf("Failed to get storage volumes: %w", err)
}

for _, pool := range poolNames {
poolID, err := tx.GetStoragePoolID(ctx, pool)
if err != nil {
return fmt.Errorf("Failed to get storage volumes: %w", err)
}

poolVolumes, err := tx.GetStoragePoolVolumes(ctx, poolID, memberSpecific, filters...)
if err != nil {
return fmt.Errorf("Failed loading storage volumes: %w", err)
}

dbVolumes = append(dbVolumes, poolVolumes...)
return fmt.Errorf("Failed loading storage volumes: %w", err)
}

return err
}

dbVolumes, err = tx.GetStoragePoolVolumes(ctx, poolID, memberSpecific, filters...)
poolFilter := db.StorageVolumeFilter{
PoolID: &poolID,
}

filters = append(filters, poolFilter)

dbVolumes, err = tx.GetStoragePoolVolumes(ctx, memberSpecific, filters...)
if err != nil {
return fmt.Errorf("Failed loading storage volumes: %w", err)
}
Expand Down

0 comments on commit f475e94

Please sign in to comment.