Skip to content

Commit 622757e

Browse files
committed
[cache] Revert to using a list for stable ordering
Do deduplication by simply iterating over the list which is fine due to the small number of available compressions (1 or 2 in the vast majority of cases) Signed-off-by: Baptiste Girard-Carrabin <[email protected]>
1 parent 0858b9e commit 622757e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cache/remote.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,19 @@ func getAvailableBlobs(ctx context.Context, cs content.Store, chain *solver.Remo
112112
if err != nil {
113113
return nil, err
114114
}
115-
var descs = map[digest.Digest]ocispecs.Descriptor{}
115+
var descs []ocispecs.Descriptor
116116
if err := walkBlob(ctx, cs, target, func(desc ocispecs.Descriptor) bool {
117117
// Nothing prevents this function from being called multiple times for the same descriptor.
118-
// Using a map will prevent duplicates in the result.
119-
descs[desc.Digest] = desc
118+
// So we need to make sure we don't add the same descriptor again.
119+
// Looping over the list is preferable:
120+
// 1. to avoid using a map, which don't preserve the order of descriptors,
121+
// 2. descs will have a length the number of compression variants for a blob, which is usually very small
122+
for _, d := range descs {
123+
if d.Digest == desc.Digest {
124+
return true // already seen this descriptor
125+
}
126+
}
127+
descs = append(descs, desc)
120128
return true
121129
}); err != nil {
122130
bklog.G(ctx).WithError(err).Warn("failed to walk variant blob") // is not a critical error at this moment.

0 commit comments

Comments
 (0)