Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
ApplicationManager.getApplication().executeOnPooledThread {
var errorMessage = ""
val profiles = try {
QRegionProfileManager.getInstance().listRegionProfiles(project)
QRegionProfileManager.getInstance().listProfilesCompletableFuture(project).get()
} catch (e: Exception) {
e.message?.let {
errorMessage = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class QRegionProfileDialog(

combo.proposeModelUpdate { model ->
try {
QRegionProfileManager.getInstance().listRegionProfiles(project)?.forEach {
QRegionProfileManager.getInstance().listProfilesCompletableFuture(project).get()?.forEach {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AwsResourceCache already limits the call to one at a time

model.addElement(it)
} ?: error("Attempted to fetch profiles while there does not exist")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import software.aws.toolkits.telemetry.MetricResult
import software.aws.toolkits.telemetry.Telemetry
import java.time.Duration
import java.util.Collections
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass

@Service(Service.Level.APP)
Expand All @@ -45,6 +46,7 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
// Map to store connectionId to its active profile
private val connectionIdToActiveProfile = Collections.synchronizedMap<String, QRegionProfile>(mutableMapOf())
private val connectionIdToProfileCount = mutableMapOf<String, Int>()
private var job: CompletableFuture<List<QRegionProfile>?>? = null

init {
ApplicationManager.getApplication().messageBus.connect(this)
Expand All @@ -65,7 +67,7 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
val conn = getIdcConnectionOrNull(project)
val selected = activeProfile(project) ?: return
val profiles = tryOrNull {
listRegionProfiles(project)
listProfilesCompletableFuture(project).get()
}

if (profiles == null || profiles.none { it.arn == selected.arn }) {
Expand Down Expand Up @@ -104,6 +106,21 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
}
}

fun listProfilesCompletableFuture(project: Project): CompletableFuture<List<QRegionProfile>?> {
this.job?.let { ongoingJob ->
return ongoingJob
}

val future = CompletableFuture.supplyAsync {
listRegionProfiles(project)
}.whenComplete { t, u ->
this.job = null
}

this.job = future
return future
}

fun activeProfile(project: Project): QRegionProfile? = getIdcConnectionOrNull(project)?.let { connectionIdToActiveProfile[it.id] }

fun hasValidConnectionButNoActiveProfile(project: Project): Boolean = getIdcConnectionOrNull(project) != null && activeProfile(project) == null
Expand Down
Loading