LoadSnapshots efficiently loads and parses a given list of snapshot IDs.
(ctx context.Context, rep repo.Repository, manifestIDs []manifest.ID)
| 150 | |
| 151 | // LoadSnapshots efficiently loads and parses a given list of snapshot IDs. |
| 152 | func LoadSnapshots(ctx context.Context, rep repo.Repository, manifestIDs []manifest.ID) ([]*Manifest, error) { |
| 153 | result := make([]*Manifest, len(manifestIDs)) |
| 154 | sem := make(chan bool, loadSnapshotsConcurrency) |
| 155 | |
| 156 | for i, n := range manifestIDs { |
| 157 | sem <- true |
| 158 | |
| 159 | go func(i int, n manifest.ID) { |
| 160 | defer func() { <-sem }() |
| 161 | |
| 162 | m, err := LoadSnapshot(ctx, rep, n) |
| 163 | if err != nil { |
| 164 | log(ctx).Errorf("unable to parse snapshot manifest %v: %v", n, err) |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | result[i] = m |
| 169 | }(i, n) |
| 170 | } |
| 171 | |
| 172 | for range cap(sem) { |
| 173 | sem <- true |
| 174 | } |
| 175 | |
| 176 | close(sem) |
| 177 | |
| 178 | successful := result[:0] |
| 179 | |
| 180 | for _, m := range result { |
| 181 | if m != nil { |
| 182 | successful = append(successful, m) |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return successful, nil |
| 187 | } |
| 188 | |
| 189 | // ListSnapshotManifests returns the list of snapshot manifests for a given source or all sources if nil. |
| 190 | func ListSnapshotManifests(ctx context.Context, rep repo.Repository, src *SourceInfo, tags map[string]string) ([]manifest.ID, error) { |