Skip to content

Commit bc265e6

Browse files
use cache to simplify implementation.
1 parent 4e05cbf commit bc265e6

File tree

6 files changed

+15
-63
lines changed

6 files changed

+15
-63
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id "org.jetbrains.intellij"
4+
id "io.freefair.aspectj.post-compile-weaving"
45
}
56

67
group 'com.microsoft.azuretools'
@@ -26,6 +27,8 @@ dependencies {
2627
exclude group: "com.fasterxml.jackson", module: "jackson-bom"
2728
}
2829

29-
implementation project(':azure-intellij-plugin-lib')
30-
implementation "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
30+
compile project(':azure-intellij-plugin-lib')
31+
compile "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
32+
33+
aspect "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
3134
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/dependencesurvey/activity/AzurePreloadingActivity.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

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

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

40+
import javax.annotation.Nonnull;
4041
import javax.swing.*;
4142
import javax.swing.tree.DefaultMutableTreeNode;
4243
import javax.swing.tree.DefaultTreeModel;
@@ -95,11 +96,9 @@ private void filter(final String text) {
9596
this.loadData(this.services, filters);
9697
}
9798

98-
public void refresh() {
99-
final AzureSdkLibraryService service = AzureSdkLibraryService.getInstance();
99+
public void refresh(Boolean... force) {
100100
try {
101-
service.reloadAzureSDKArtifacts();
102-
this.services = service.getServices();
101+
this.services = AzureSdkLibraryService.loadAzureSdkServices(force);
103102
this.filter.debounce();
104103
Optional.ofNullable(this.lastNodePath).ifPresent(p -> TreeUtil.selectPath(this.tree, p));
105104
} catch (final IOException e) {
@@ -176,7 +175,7 @@ public final void actionPerformed(@NotNull final AnActionEvent e) {
176175
this.loading = true;
177176
ActivityTracker.getInstance().inc();
178177
AzureTaskManager.getInstance().runLater(() -> {
179-
AzureSdkTreePanel.this.refresh();
178+
AzureSdkTreePanel.this.reload();
180179
this.loading = false;
181180
});
182181
}

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,21 @@
1111
import com.fasterxml.jackson.databind.ObjectReader;
1212
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1313
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity;
14+
import com.microsoft.azure.toolkit.lib.common.cache.Cacheable;
1415

1516
import java.io.IOException;
1617
import java.net.URL;
17-
import java.util.ArrayList;
18-
import java.util.Collections;
1918
import java.util.List;
2019

2120
public class AzureSdkLibraryService {
2221
private static final ObjectMapper mapper = new YAMLMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2322
private static final String SDK_METADATA_URL = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/spring/spring-reference.yml";
24-
private List<AzureSdkServiceEntity> services = new ArrayList<>();
2523

26-
public static AzureSdkLibraryService getInstance() {
27-
return Holder.instance;
28-
}
29-
30-
public List<AzureSdkServiceEntity> getServices() {
31-
return Collections.unmodifiableList(services);
32-
}
33-
34-
public void reloadAzureSDKArtifacts() throws IOException {
24+
@Cacheable(value = "sdk-services", condition = "!(force&&force[0])")
25+
public static List<AzureSdkServiceEntity> loadAzureSdkServices(boolean... force) throws IOException {
3526
final URL destination = new URL(SDK_METADATA_URL);
3627
final ObjectReader reader = mapper.readerFor(AzureSdkServiceEntity.class);
3728
final MappingIterator<AzureSdkServiceEntity> data = reader.readValues(destination);
38-
synchronized (this) {
39-
this.services = data.readAll();
40-
}
41-
}
42-
43-
private static class Holder {
44-
private static final AzureSdkLibraryService instance = new AzureSdkLibraryService();
29+
return data.readAll();
4530
}
4631
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/resources/META-INF/azure-sdk-reference-book.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<idea-plugin>
22
<extensionPoints>
33
</extensionPoints>
4-
<extensions defaultExtensionNs="com.intellij">
5-
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.azuresdk.dependencesurvey.activity.AzurePreloadingActivity"/>
6-
</extensions>
74
<actions>
85
<action id="AzureToolkit.OpenSdkReferenceBook"
96
class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.OpenReferenceBookAction"

PluginsAndFeatures/azure-toolkit-for-intellij/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ configurations {
9898
apply plugin: 'java'
9999

100100
dependencies {
101-
implementation project(':azure-intellij-plugin-lib')
102-
implementation project(':azure-sdk-reference-book')
101+
compile project(':azure-intellij-plugin-lib')
102+
compile project(':azure-sdk-reference-book')
103103
compile 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8'
104104
compile 'commons-io:commons-io:2.7'
105105
compile group: 'org.apache.commons', name: 'commons-text', version: '1.8'

0 commit comments

Comments
 (0)