fix: runtime caching for catalogue generation

This commit is contained in:
decentral1se 2021-12-26 04:01:02 +01:00
parent 9f70a69bbf
commit 3f35510507
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 16 additions and 8 deletions

View File

@ -410,6 +410,7 @@ func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
logrus.Fatal(err)
}
queryCache := make(map[reference.Named]string)
versionMeta := make(map[string]ServiceMeta)
for _, service := range recipe.Config.Services {
@ -432,12 +433,21 @@ func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
continue
}
logrus.Debugf("looking up image: %s from %s", img, path)
digest, err := client.GetTagDigest(cl, img)
if err != nil {
logrus.Warn(err)
continue
var exists bool
var digest string
if digest, exists = queryCache[img]; !exists {
logrus.Debugf("looking up image: %s from %s", img, path)
var err error
digest, err = client.GetTagDigest(cl, img)
if err != nil {
logrus.Warn(err)
continue
}
logrus.Debugf("queried for image: %s, tag: %s, digest: %s", path, tag, digest)
queryCache[img] = digest
logrus.Debugf("cached image: %s, tag: %s, digest: %s", path, tag, digest)
} else {
logrus.Debugf("reading image: %s, tag: %s, digest: %s from cache", path, tag, digest)
}
versionMeta[service.Name] = ServiceMeta{
@ -445,8 +455,6 @@ func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
Image: path,
Tag: img.(reference.NamedTagged).Tag(),
}
logrus.Debugf("collecting digest: %s, image: %s, tag: %s", digest, path, tag)
}
versions = append(versions, map[string]map[string]ServiceMeta{tag: versionMeta})