Skip to content

Commit

Permalink
Cache loaded repos in ProvisioningContext
Browse files Browse the repository at this point in the history
Currently if fetching updates the provision context is queried multiple
times leading to the repositories loaded multiple times, even though
this is usually faster as repo are cached this still produces
unnecessary workload, especially if there is one failed repository it
will be tried to be loaded over and over again.

This now caches the repositories loaded on first access to speed that
up.
  • Loading branch information
laeubi committed May 16, 2024
1 parent 5364d5d commit 0516ae1
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,22 @@ private void getLoadedRepository(URI location, IArtifactRepositoryManager repoMa
}

private Set<IMetadataRepository> getLoadedMetadataRepositories(IProgressMonitor monitor) {
IMetadataRepositoryManager repoManager = agent.getService(IMetadataRepositoryManager.class);
URI[] repositories = metadataRepositories == null ? repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL) : metadataRepositories;

Map<String, IMetadataRepository> repos = new HashMap<>();
SubMonitor sub = SubMonitor.convert(monitor, repositories.length);

// Clear out the list of remembered artifact repositories
referencedArtifactRepositories = new HashMap<>();
for (URI repositorie : repositories) {
loadMetadataRepository(repoManager, repositorie, repos, shouldFollowReferences(), sub.split(1));
if (loadedRepos == null) {
IMetadataRepositoryManager repoManager = agent.getService(IMetadataRepositoryManager.class);
URI[] repositories = metadataRepositories == null
? repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)
: metadataRepositories;

loadedRepos = new HashMap<>();
SubMonitor sub = SubMonitor.convert(monitor, repositories.length);

// Clear out the list of remembered artifact repositories
referencedArtifactRepositories = new HashMap<>();
for (URI repositorie : repositories) {
loadMetadataRepository(repoManager, repositorie, loadedRepos, shouldFollowReferences(), sub.split(1));
}
}
return new HashSet<>(repos.values());
return new HashSet<>(loadedRepos.values());
}

private void loadMetadataRepository(IMetadataRepositoryManager manager, URI location,
Expand Down Expand Up @@ -421,6 +425,7 @@ private <T, R extends IRepository<T>> void loadRepository(IRepositoryManager<T>
private static final Comparator<IArtifactKey> ARTIFACT_KEY_COMPARATOR = Comparator //
.comparing(IArtifactKey::getId) //
.thenComparing(IArtifactKey::getVersion);
private Map<String, IMetadataRepository> loadedRepos;

/**
* Returns a map from simple artifact repository location to a subset of the
Expand Down

0 comments on commit 0516ae1

Please sign in to comment.