Preload missing resources

There are some inconsistencies in the way the API returns some
values for pools and scale sets. This is due to not preloading
the appropriate relations.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-08-12 09:15:58 +00:00
parent 9f2764f614
commit b2dee1d844
5 changed files with 29 additions and 4 deletions

View file

@ -330,6 +330,8 @@ func (s *sqlDatabase) sqlToCommonPool(pool Pool) (params.Pool, error) {
func (s *sqlDatabase) sqlToCommonScaleSet(scaleSet ScaleSet) (params.ScaleSet, error) {
ret := params.ScaleSet{
ID: scaleSet.ID,
CreatedAt: scaleSet.CreatedAt,
UpdatedAt: scaleSet.UpdatedAt,
ScaleSetID: scaleSet.ScaleSetID,
Name: scaleSet.Name,
DisableUpdate: scaleSet.DisableUpdate,
@ -355,24 +357,33 @@ func (s *sqlDatabase) sqlToCommonScaleSet(scaleSet ScaleSet) (params.ScaleSet, e
DesiredRunnerCount: scaleSet.DesiredRunnerCount,
}
var ep GithubEndpoint
if scaleSet.RepoID != nil {
ret.RepoID = scaleSet.RepoID.String()
if scaleSet.Repository.Owner != "" && scaleSet.Repository.Name != "" {
ret.RepoName = fmt.Sprintf("%s/%s", scaleSet.Repository.Owner, scaleSet.Repository.Name)
}
ep = scaleSet.Repository.Endpoint
}
if scaleSet.OrgID != nil {
ret.OrgID = scaleSet.OrgID.String()
ret.OrgName = scaleSet.Organization.Name
ep = scaleSet.Organization.Endpoint
}
if scaleSet.EnterpriseID != nil {
ret.EnterpriseID = scaleSet.EnterpriseID.String()
ret.EnterpriseName = scaleSet.Enterprise.Name
ep = scaleSet.Enterprise.Endpoint
}
var err error
endpoint, err := s.sqlToCommonGithubEndpoint(ep)
if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "converting endpoint")
}
ret.Endpoint = endpoint
for idx, inst := range scaleSet.Instances {
ret.Instances[idx], err = s.sqlToParamsInstance(inst)
if err != nil {