From e8475ad355de1e007ad08a795f31edd0dc8c7271 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 19 Oct 2017 14:30:57 +0200 Subject: [PATCH] SONAR-9939 Don't refresh update center on edition preview --- .../java/org/sonar/server/edition/ws/PreviewAction.java | 2 ++ .../org/sonar/server/plugins/edition/EditionInstaller.java | 6 +++++- .../sonar/server/plugins/edition/EditionInstallerTest.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/PreviewAction.java b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/PreviewAction.java index e5de17fa81a..399d0fc311d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/PreviewAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/PreviewAction.java @@ -93,6 +93,8 @@ public class PreviewAction implements EditionsWsAction { private NextState computeNextState(License newLicense) { if (!editionInstaller.requiresInstallationChange(newLicense.getPluginKeys())) { return new NextState(newLicense.getEditionKey(), NO_INSTALL); + // this won't refresh the update center (uses cached state). Preview is called while typing (must be fast) + // and anyway the status is refreshed when arriving at the marketplace page. } else if (editionInstaller.isOffline()) { return new NextState(newLicense.getEditionKey(), MANUAL_INSTALL); } else { diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java index f72e157ee45..5fac04557c2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java @@ -82,8 +82,12 @@ public class EditionInstaller { uninstallPlugins(pluginsToRemove); } + /** + * Check if the update center is disabled or unreachable. It uses the cached status (it doesn't refresh), + * to be a cost-free check. + */ public boolean isOffline() { - return !updateCenterMatrixFactory.getUpdateCenter(true).isPresent(); + return !updateCenterMatrixFactory.getUpdateCenter(false).isPresent(); } public boolean requiresInstallationChange(Set editionPluginKeys) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java index e4c0603642f..b897d1b131f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionInstallerTest.java @@ -122,7 +122,7 @@ public class EditionInstallerTest { @Test public void is_offline() { - when(updateCenterMatrixFactory.getUpdateCenter(true)).thenReturn(Optional.absent()); + when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.absent()); assertThat(installer.isOffline()).isTrue(); } -- 2.39.5