diff --git a/api/v1/v1.go b/api/v1/v1.go index ef9fe5e..f2c4ed7 100644 --- a/api/v1/v1.go +++ b/api/v1/v1.go @@ -113,6 +113,13 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) { return nil, err } + type rtags struct { + ref string + tags []*tag.Tag + } + + tagc := make(chan rtags, len(refs)) + tags := make(map[string][]*tag.Tag) batchedSlicesOfRefs := getBatchedSlices(api.config.ConcurrentRequests, refs...) @@ -151,10 +158,9 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) { localTags, repo.Tags(), ) - log.Debugf("%s joined tags: %+v", fn(repo.Ref()), joinedTags) - - tags[repo.Ref()] = tag.Collect(sortedKeys, tagNames, joinedTags) + log.Debugf("%s sending joined tags: %+v", fn(repo.Ref()), joinedTags) + tagc <- rtags{ref: repo.Ref(), tags: tag.Collect(sortedKeys, tagNames, joinedTags)} done <- nil log.Infof("FETCHED %s", repo.Ref()) @@ -168,6 +174,20 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) { } } + step := 1 + size := cap(tagc) + for t := range tagc { + log.Debugf("[%s] receiving tags: %+v", t.ref, t.tags) + + tags[t.ref] = t.tags + + if step >= size { + close(tagc) + } + + step++ + } + log.Debugf("%s tags: %+v", fn(), tags) return collection.New(refs, tags) diff --git a/tag/remote/remote.go b/tag/remote/remote.go index a47b895..d40eaec 100644 --- a/tag/remote/remote.go +++ b/tag/remote/remote.go @@ -109,8 +109,10 @@ func httpRetriableRequest(url, authorization, mode string) (*http.Response, erro return resp, nil } - if resp.StatusCode >= 400 && resp.StatusCode < 500 { - return nil, err + if resp != nil { + if resp.StatusCode >= 400 && resp.StatusCode < 500 { + return nil, err + } } if try < tries {