Skip to content

Commit 6bbb2ca

Browse files
committed
Optimize app generation detection by using AppInfo response
- Use app.Generation.Name directly from AppInfo response instead of making separate SpaceInfo API call - Remove unnecessary getSpaceGeneration() function and SpaceInfo API request - Maintains same functionality with better performance and fewer API calls - Addresses PR feedback about unnecessary API requests
1 parent 6eddd63 commit 6bbb2ca

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

heroku/resource_heroku_app.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,13 @@ func (a *application) Update() error {
639639

640640
if app.Space != nil {
641641
a.App.Space = app.Space.Name
642-
// Determine generation from space information
643-
spaceGeneration, err := a.getSpaceGeneration(app.Space.ID)
644-
if err != nil {
645-
log.Printf("[WARN] Could not determine space generation for %s: %s", app.Space.ID, err)
646-
a.Generation = "cedar" // Default to cedar if we can't determine
647-
} else {
648-
a.Generation = spaceGeneration
649-
}
642+
}
643+
644+
// Determine generation from app's generation field (available in AppInfo response)
645+
if app.Generation.Name != "" {
646+
a.Generation = app.Generation.Name
650647
} else {
651-
// Apps not in a space are cedar generation (common app platform)
648+
// Default to cedar if generation is not specified
652649
a.Generation = "cedar"
653650
}
654651

@@ -725,22 +722,6 @@ func isCNBError(err error) bool {
725722
strings.Contains(errorMessage, "project.toml")
726723
}
727724

728-
// getSpaceGeneration determines the generation of a space by querying the space API
729-
func (a *application) getSpaceGeneration(spaceID string) (string, error) {
730-
space, err := a.Client.SpaceInfo(context.TODO(), spaceID)
731-
if err != nil {
732-
return "", fmt.Errorf("failed to get space info: %w", err)
733-
}
734-
735-
// Check if the space has generation information
736-
if space.Generation.Name != "" {
737-
return space.Generation.Name, nil
738-
}
739-
740-
// Default to cedar if generation is not specified
741-
return "cedar", nil
742-
}
743-
744725
func retrieveAcm(id string, client *heroku.Service) (bool, error) {
745726
result, err := client.AppInfo(context.TODO(), id)
746727
if err != nil {

0 commit comments

Comments
 (0)