From: Duarte Meneses Date: Thu, 19 Oct 2017 12:30:57 +0000 (+0200) Subject: SONAR-9939 Don't refresh update center on edition preview X-Git-Tag: 6.7-RC1~81 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e8475ad355de1e007ad08a795f31edd0dc8c7271;p=sonarqube.git SONAR-9939 Don't refresh update center on edition preview --- 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(); }