(
ctx context.Context,
registryDao store.RegistryRepository,
f func(registry registrytypes.Registry, a pkg.Artifact, limit, offset int) response.Response,
extractResponseDataFunc func(searchResponse response.Response) ([]interface{}, int64),
info pkg.PackageArtifactInfo,
limit int,
offset int,
)
| 181 | } |
| 182 | |
| 183 | func SearchPackagesProxyWrapper( |
| 184 | ctx context.Context, |
| 185 | registryDao store.RegistryRepository, |
| 186 | f func(registry registrytypes.Registry, a pkg.Artifact, limit, offset int) response.Response, |
| 187 | extractResponseDataFunc func(searchResponse response.Response) ([]interface{}, int64), |
| 188 | info pkg.PackageArtifactInfo, |
| 189 | limit int, |
| 190 | offset int, |
| 191 | ) ([]interface{}, int64, error) { |
| 192 | requestRepoKey := info.BaseArtifactInfo().RegIdentifier |
| 193 | |
| 194 | // Get all registries (local + proxies) - Z = [x, p1, p2, p3...] |
| 195 | registries, skipped, err := filterRegs(ctx, registryDao, requestRepoKey, info, true) |
| 196 | if err != nil { |
| 197 | return nil, 0, err |
| 198 | } |
| 199 | |
| 200 | // Pre-allocate slice for aggregated results (generic interface{}) |
| 201 | var aggregatedResults []interface{} |
| 202 | var totalCount int64 |
| 203 | |
| 204 | currentOffset := offset |
| 205 | remainingLimit := limit |
| 206 | |
| 207 | // Loop through each registry R in Z |
| 208 | for _, registry := range registries { |
| 209 | if remainingLimit <= 0 { |
| 210 | break |
| 211 | } |
| 212 | |
| 213 | log.Ctx(ctx).Info().Msgf("Searching in Registry: %s, Type: %s", registry.Name, registry.Type) |
| 214 | art := GetArtifactRegistry(registry) |
| 215 | if art == nil { |
| 216 | log.Ctx(ctx).Warn().Msgf("No artifact registry found for: %s", registry.Name) |
| 217 | continue |
| 218 | } |
| 219 | |
| 220 | // 1. Call f with remainingLimit and currentOffset |
| 221 | searchResponse := f(registry, art, remainingLimit, currentOffset) |
| 222 | if searchResponse.GetError() != nil { |
| 223 | log.Ctx(ctx).Warn().Msgf("Search failed for registry %s: %v", registry.Name, searchResponse.GetError()) |
| 224 | continue |
| 225 | } |
| 226 | |
| 227 | // Extract response data using the provided function |
| 228 | nativeResults, totalHits := extractResponseDataFunc(searchResponse) |
| 229 | resultsSize := len(nativeResults) |
| 230 | totalCount += totalHits |
| 231 | |
| 232 | if resultsSize == 0 { |
| 233 | continue |
| 234 | } |
| 235 | |
| 236 | // 2. Append search results (preserve native types) |
| 237 | aggregatedResults = append(aggregatedResults, nativeResults...) |
| 238 | |
| 239 | // 3. Update currentOffset = max(0, currentOffset - registryResults.size) |
| 240 | currentOffset = max(0, currentOffset-resultsSize) |
no test coverage detected
searching dependent graphs…