Do the project iteration on Gerrit startup in background
On Gerrit startup the plugin iterates over all projects and schedules
for each project a background job to scan for project-specific
download commands. Although the actual scanning is done in background
the iteration over all projects and the scheduling of the background
jobs may take a long time. Improve the Gerrit startup time by moving
the iteration over all projects into a background job that then does
the scanning for project-specific download commands on all projects.
Change-Id: I38e6005568f990ec816f4af43f40cb77091a2483
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java
index 125426e..ce0f857 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java
@@ -73,12 +73,22 @@
@Override
public void start() {
- for (Project.NameKey p : projectCache.all()) {
- ProjectState projectState = projectCache.get(p);
- if (projectState != null) {
- installCommandAsync(projectState);
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ for (Project.NameKey p : projectCache.all()) {
+ ProjectState projectState = projectCache.get(p);
+ if (projectState != null) {
+ PluginConfig cfg =
+ projectState.getConfig().getPluginConfig(pluginName);
+ for (String name : cfg.getNames()) {
+ installCommand(projectState.getProject().getNameKey(), name,
+ cfg.getString(name));
+ }
+ }
+ }
}
- }
+ });
}
@Override
@@ -117,18 +127,6 @@
}
}
- private void installCommandAsync(final ProjectState p) {
- executor.submit(new Runnable() {
- @Override
- public void run() {
- PluginConfig cfg = p.getConfig().getPluginConfig(pluginName);
- for (String name : cfg.getNames()) {
- installCommand(p.getProject().getNameKey(), name, cfg.getString(name));
- }
- }
- });
- }
-
private void installCommand(final Project.NameKey p, String name,
final String command) {
ProjectDownloadCommand dc = projectDownloadCommands.get(name);