From 2c540bdc9d3c53c63afa2d3e875a2c2cb3e36bcd Mon Sep 17 00:00:00 2001 From: Jonathan Giannuzzi Date: Wed, 15 Sep 2021 14:08:26 +0100 Subject: [PATCH] Fix issues #1980 and #2198 Signed-off-by: Jonathan Giannuzzi --- cache/remotecache/v1/cachestorage.go | 54 +++++++++++++++------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/cache/remotecache/v1/cachestorage.go b/cache/remotecache/v1/cachestorage.go index dee02f4b3699..7512b15e796f 100644 --- a/cache/remotecache/v1/cachestorage.go +++ b/cache/remotecache/v1/cachestorage.go @@ -214,35 +214,41 @@ func (cs *cacheResultStorage) Save(res solver.Result, createdAt time.Time) (solv } func (cs *cacheResultStorage) LoadWithParents(ctx context.Context, res solver.CacheResult) (map[string]solver.Result, error) { - v := cs.byResultID(res.ID) - if v == nil || v.result == nil { - return nil, errors.WithStack(solver.ErrNotFound) - } - m := map[string]solver.Result{} visited := make(map[*item]struct{}) - if err := v.walkAllResults(func(i *item) error { - if i.result == nil { - return nil - } - id, ok := cs.byItem[i] - if !ok { - return nil - } - if isSubRemote(*i.result, *v.result) { - ref, err := cs.w.FromRemote(ctx, i.result) - if err != nil { - return err + + ids, ok := cs.byResult[res.ID] + if !ok || len(ids) == 0 { + return nil, errors.WithStack(solver.ErrNotFound) + } + + for id := range ids { + v, ok := cs.byID[id] + if ok && v.result != nil { + if err := v.walkAllResults(func(i *item) error { + if i.result == nil { + return nil + } + id, ok := cs.byItem[i] + if !ok { + return nil + } + if isSubRemote(*i.result, *v.result) { + ref, err := cs.w.FromRemote(ctx, i.result) + if err != nil { + return err + } + m[id] = worker.NewWorkerRefResult(ref, cs.w) + } + return nil + }, visited); err != nil { + for _, v := range m { + v.Release(context.TODO()) + } + return nil, err } - m[id] = worker.NewWorkerRefResult(ref, cs.w) - } - return nil - }, visited); err != nil { - for _, v := range m { - v.Release(context.TODO()) } - return nil, err } return m, nil