Skip to content

Commit 7a7b578

Browse files
committed
fix heavy checking on sql region combo box.
1 parent 14b0c24 commit 7a7b578

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/sqlserver/common/SqlServerRegionComboBox.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
import java.util.Objects;
2222
import java.util.stream.Collectors;
2323

24+
/**
25+
* TODO(Qianjin) : extend RegionComboBox
26+
*/
2427
public class SqlServerRegionComboBox extends AzureComboBox<Region> {
2528

2629
private static final String REGION_UNAVAILABLE_MESSAGE = "Your subscription does not have access to create a server "
2730
+ "in the selected region. For the latest information about region availability for your subscription, go to "
2831
+ "aka.ms/sqlcapacity. Please try another region or create a support ticket to request access.";
2932

3033
private Subscription subscription;
34+
private boolean validated;
35+
private AzureValidationInfo validatedInfo;
3136

3237
public void setSubscription(Subscription subscription) {
3338
if (Objects.equals(subscription, this.subscription)) {
@@ -62,6 +67,14 @@ protected String getItemText(Object item) {
6267
return super.getItemText(item);
6368
}
6469

70+
@Override
71+
public void setItem(Region item) {
72+
if (!item.equals(getItem())) {
73+
validated = false;
74+
}
75+
super.setItem(item);
76+
}
77+
6578
@Override
6679
public boolean isRequired() {
6780
return true;
@@ -70,16 +83,19 @@ public boolean isRequired() {
7083
@NotNull
7184
@Override
7285
public AzureValidationInfo doValidate() {
73-
final AzureValidationInfo info = super.doValidate();
74-
if (!AzureValidationInfo.OK.equals(info)) {
75-
return info;
86+
if (validated && Objects.isNull(validatedInfo)) {
87+
return validatedInfo;
7688
}
77-
AzureSqlServer service = com.microsoft.azure.toolkit.lib.Azure.az(AzureSqlServer.class);
78-
if (!service.checkRegionCapability(subscription.subscriptionId(), getValue().getName())) {
79-
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
80-
return builder.input(this).message(REGION_UNAVAILABLE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
89+
validatedInfo = super.doValidate();
90+
if (AzureValidationInfo.OK.equals(validatedInfo)) {
91+
AzureSqlServer service = com.microsoft.azure.toolkit.lib.Azure.az(AzureSqlServer.class);
92+
if (!service.checkRegionCapability(subscription.subscriptionId(), getValue().getName())) {
93+
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
94+
validatedInfo = builder.input(this).message(REGION_UNAVAILABLE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
95+
}
8196
}
82-
return info;
97+
validated = true;
98+
return validatedInfo;
8399
}
84100

85101
/**

0 commit comments

Comments
 (0)