Skip to content

Commit c123680

Browse files
make use of PreloadingActivity+@preload to achieve cache warmup
1 parent bc265e6 commit c123680

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.preload;
7+
8+
import com.intellij.openapi.application.ApplicationManager;
9+
import com.intellij.openapi.application.PreloadingActivity;
10+
import com.intellij.openapi.progress.ProgressIndicator;
11+
import com.microsoft.azure.toolkit.lib.common.cache.Preloader;
12+
import lombok.extern.java.Log;
13+
14+
@Log
15+
public class AzurePreloadingActivity extends PreloadingActivity {
16+
17+
@Override
18+
public void preload(@org.jetbrains.annotations.NotNull final ProgressIndicator indicator) {
19+
// Using progress manager as azure task manager is not initialized
20+
ApplicationManager.getApplication().executeOnPooledThread(Preloader::load);
21+
}
22+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/resources/META-INF/azure-intellij-plugin-lib.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<extensionPoints>
33
</extensionPoints>
44
<extensions defaultExtensionNs="com.intellij">
5+
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.common.preload.AzurePreloadingActivity"/>
56
</extensions>
67
<actions>
78
</actions>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkTreePanel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.commons.lang3.StringUtils;
3838
import org.jetbrains.annotations.NotNull;
3939

40-
import javax.annotation.Nonnull;
4140
import javax.swing.*;
4241
import javax.swing.tree.DefaultMutableTreeNode;
4342
import javax.swing.tree.DefaultTreeModel;
@@ -96,7 +95,7 @@ private void filter(final String text) {
9695
this.loadData(this.services, filters);
9796
}
9897

99-
public void refresh(Boolean... force) {
98+
public void refresh(boolean... force) {
10099
try {
101100
this.services = AzureSdkLibraryService.loadAzureSdkServices(force);
102101
this.filter.debounce();
@@ -175,7 +174,7 @@ public final void actionPerformed(@NotNull final AnActionEvent e) {
175174
this.loading = true;
176175
ActivityTracker.getInstance().inc();
177176
AzureTaskManager.getInstance().runLater(() -> {
178-
AzureSdkTreePanel.this.reload();
177+
AzureSdkTreePanel.this.refresh(true);
179178
this.loading = false;
180179
});
181180
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/service/AzureSdkLibraryService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1313
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity;
1414
import com.microsoft.azure.toolkit.lib.common.cache.Cacheable;
15+
import com.microsoft.azure.toolkit.lib.common.cache.Preload;
1516

1617
import java.io.IOException;
1718
import java.net.URL;
@@ -21,6 +22,7 @@ public class AzureSdkLibraryService {
2122
private static final ObjectMapper mapper = new YAMLMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2223
private static final String SDK_METADATA_URL = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/spring/spring-reference.yml";
2324

25+
@Preload
2426
@Cacheable(value = "sdk-services", condition = "!(force&&force[0])")
2527
public static List<AzureSdkServiceEntity> loadAzureSdkServices(boolean... force) throws IOException {
2628
final URL destination = new URL(SDK_METADATA_URL);

0 commit comments

Comments
 (0)