From 3f3551050740add8a2aec82e04870823f110a111 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Sun, 26 Dec 2021 04:01:02 +0100 Subject: [PATCH] fix: runtime caching for catalogue generation --- pkg/catalogue/catalogue.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/catalogue/catalogue.go b/pkg/catalogue/catalogue.go index 119bca21..0f895ea2 100644 --- a/pkg/catalogue/catalogue.go +++ b/pkg/catalogue/catalogue.go @@ -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})