Skip to content

Commit

Permalink
api: fix slow version endpoint
Browse files Browse the repository at this point in the history
This endpoint queried the same package versions twice causing it to be
slower than info. Because it already called info we can just reuse the
package versions from there.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 authored and ashley-cui committed Jul 13, 2023
1 parent 28e92b9 commit a3a6285
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions pkg/api/handlers/compat/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/entities/types"
"github.com/containers/podman/v4/version"
"github.com/sirupsen/logrus"
)

func VersionHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -45,30 +44,20 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
"MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
"Os": goRuntime.GOOS,
},
}, {
Name: "Conmon",
Version: info.Host.Conmon.Version,
Details: map[string]string{
"Package": info.Host.Conmon.Package,
},
}, {
Name: fmt.Sprintf("OCI Runtime (%s)", info.Host.OCIRuntime.Name),
Version: info.Host.OCIRuntime.Version,
Details: map[string]string{
"Package": info.Host.OCIRuntime.Package,
},
}}

if conmon, oci, err := runtime.DefaultOCIRuntime().RuntimeInfo(); err != nil {
logrus.Warnf("Failed to retrieve Conmon and OCI Information: %q", err.Error())
} else {
additional := []types.ComponentVersion{
{
Name: "Conmon",
Version: conmon.Version,
Details: map[string]string{
"Package": conmon.Package,
},
},
{
Name: fmt.Sprintf("OCI Runtime (%s)", oci.Name),
Version: oci.Version,
Details: map[string]string{
"Package": oci.Package,
},
},
}
components = append(components, additional...)
}

apiVersion := version.APIVersion[version.Compat][version.CurrentAPI]
minVersion := version.APIVersion[version.Compat][version.MinimalAPI]

Expand Down

0 comments on commit a3a6285

Please sign in to comment.