weldr: Preload metadata at startup

For each of the supported distros start a goroutine to depsolve
'filesystem' which will preload the metadata making subsequent responses
faster.

This is safe to do without limits because we only supposed a limited
number of distros, and without additional locking because this is the
the same as hitting the API with multiple depsolve requests at the same
time.
This commit is contained in:
Brian C. Lane 2022-08-29 14:13:54 -07:00 committed by Tom Gundersen
parent c864343770
commit c32f94d6f2
2 changed files with 29 additions and 0 deletions

View file

@ -123,6 +123,8 @@ func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener,
}
c.weldrListener = weldrListener
// Preload the Metadata for all the supported distros
c.weldr.PreloadMetadata()
return nil
}

View file

@ -299,6 +299,33 @@ func (api *API) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
api.router.ServeHTTP(writer, request)
}
// PreloadMetadata loads the metadata for all supported distros
// This starts a background depsolve for all known distros in order to preload the
// metadata.
func (api *API) PreloadMetadata() {
for _, distro := range api.distros {
go func(distro string) {
d := api.getDistro(distro)
if d == nil {
log.Printf("GetDistro - unknown distribution: %s", distro)
return
}
repos, err := api.allRepositories(distro)
if err != nil {
log.Printf("Error getting repositories for distro %s: %s", distro, err)
return
}
solver := api.solver.NewWithConfig(d.ModulePlatformID(), d.Releasever(), api.archName)
_, err = solver.Depsolve([]rpmmd.PackageSet{{Include: []string{"filesystem"}, Repositories: repos}})
if err != nil {
log.Printf("Problem preloading distro metadata for %s: %s", distro, err)
}
}(distro)
}
}
type composeStatus struct {
State ComposeState
Queued time.Time