Skip to content
Permalink
Browse files

[JENKINS-51205] Improve performance of /pluginManager/available service.

  • Loading branch information
jglick committed May 8, 2018
1 parent afb71c0 commit 3b61b96119b9fd8c80b1fa79a19f8f770af434b7
@@ -144,6 +144,7 @@
import java.net.JarURLConnection;
import java.net.URLConnection;
import java.util.ServiceLoader;
import java.util.function.Supplier;
import java.util.jar.JarEntry;

import static java.util.logging.Level.FINE;
@@ -1816,6 +1817,19 @@ public HttpResponse doInstallNecessaryPlugins(StaplerRequest req) throws IOExcep
return requestedPlugins;
}

@Restricted(DoNotUse.class) // table.jelly
public MetadataCache createCache() {
return new MetadataCache();
}

@Restricted(NoExternalUse.class) // table.jelly
public static final class MetadataCache {
private final Map<String, Object> data = new HashMap<>();
public <T> T of(String key, Class<T> type, Supplier<T> func) {
return type.cast(data.computeIfAbsent(key, _ignored -> func.get()));
}
}

/**
* {@link ClassLoader} that can see all plugins.
*/
@@ -120,11 +120,6 @@
*/
private transient volatile long retryWindow;

/**
* lastModified time of the data file when it was last read.
*/
private transient long dataLastReadFromFile;

/**
* Latest data as read from the data file.
*/
@@ -226,6 +221,7 @@ private FormValidation updateData(String json, boolean signatureCheck)
LOGGER.info("Obtained the latest update center data file for UpdateSource " + id);
retryWindow = 0;
getDataFile().write(json);
data = new Data(o);
return FormValidation.ok();
}

@@ -309,23 +305,20 @@ public boolean isDue() {
public HttpResponse doInvalidateData() {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
dataTimestamp = 0;
data = null;
return HttpResponses.ok();
}

/**
* Loads the update center data, if any and if modified since last read.
* Loads the update center data, if any.
*
* @return null if no data is available.
*/
public Data getData() {
TextFile df = getDataFile();
if (df.exists() && dataLastReadFromFile != df.file.lastModified()) {
if (data == null) {
JSONObject o = getJSONObject();
if (o!=null) {
if (o != null) {
data = new Data(o);
dataLastReadFromFile = df.file.lastModified();
} else {
data = null;
}
}
return data;
@@ -1094,10 +1087,19 @@ public VersionNumber getNeededDependenciesRequiredCore() {
}

public boolean isNeededDependenciesForNewerJenkins() {
for (Plugin p: getNeededDependencies()) {
if (p.isForNewerHudson() || p.isNeededDependenciesForNewerJenkins()) return true;
}
return false;
return isNeededDependenciesForNewerJenkins(new PluginManager.MetadataCache());
}

@Restricted(NoExternalUse.class) // table.jelly
public boolean isNeededDependenciesForNewerJenkins(PluginManager.MetadataCache cache) {
return cache.of("isNeededDependenciesForNewerJenkins:" + name, Boolean.class, () -> {
for (Plugin p : getNeededDependencies()) {
if (p.isForNewerHudson() || p.isNeededDependenciesForNewerJenkins()) {
return true;
}
}
return false;
});
}

/**
@@ -1109,11 +1111,19 @@ public boolean isNeededDependenciesForNewerJenkins() {
* specified, it'll return true.
*/
public boolean isNeededDependenciesCompatibleWithInstalledVersion() {
for (Plugin p: getNeededDependencies()) {
if (!p.isCompatibleWithInstalledVersion() || !p.isNeededDependenciesCompatibleWithInstalledVersion())
return false;
}
return true;
return isNeededDependenciesCompatibleWithInstalledVersion(new PluginManager.MetadataCache());
}

@Restricted(NoExternalUse.class) // table.jelly
public boolean isNeededDependenciesCompatibleWithInstalledVersion(PluginManager.MetadataCache cache) {
return cache.of("isNeededDependenciesCompatibleWithInstalledVersion:" + name, Boolean.class, () -> {
for (Plugin p : getNeededDependencies()) {
if (!p.isCompatibleWithInstalledVersion() || !p.isNeededDependenciesCompatibleWithInstalledVersion()) {
return false;
}
}
return true;
});
}

/**
@@ -72,6 +72,7 @@ THE SOFTWARE.
<j:choose>
<j:when test="${!empty(list)}">
<j:set var="lastCat" value="" />
<j:set var="cache" value="${it.createCache()}"/>
<j:forEach var="p" items="${list}">
<j:if test="${!isUpdates}">
<j:set var="thisCat" value="${p.category}" />
@@ -105,10 +106,10 @@ THE SOFTWARE.
<j:if test="${p.isForNewerHudson()}">
<div class="compatWarning">${%coreWarning(p.requiredCore)}</div>
</j:if>
<j:if test="${!p.isNeededDependenciesCompatibleWithInstalledVersion()}">
<j:if test="${!p.isNeededDependenciesCompatibleWithInstalledVersion(cache)}">
<div class="compatWarning">${%depCompatWarning}</div>
</j:if>
<j:if test="${p.isNeededDependenciesForNewerJenkins()}">
<j:if test="${p.isNeededDependenciesForNewerJenkins(cache)}">
<div class="compatWarning">${%depCoreWarning(p.getNeededDependenciesRequiredCore().toString())}</div>
</j:if>
<j:if test="${p.hasWarnings()}">

0 comments on commit 3b61b96

Please sign in to comment.
You can’t perform that action at this time.