Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -15,6 +15,7 @@
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import com.intellij.util.xmlb.annotations.MapAnnotation
import com.intellij.util.xmlb.annotations.Property
import kotlinx.coroutines.CoroutineScope
import software.amazon.awssdk.core.SdkClient
import software.aws.toolkits.core.TokenConnectionSettings
import software.aws.toolkits.core.utils.debug
Expand All @@ -36,15 +37,18 @@
import software.aws.toolkits.telemetry.Telemetry
import java.time.Duration
import java.util.Collections
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Future

Check warning on line 41 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QRegionProfileManager.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import kotlin.reflect.KClass

@Service(Service.Level.APP)
@State(name = "qProfileStates", storages = [Storage("aws.xml")])
class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposable {
class QRegionProfileManager(private val cs: CoroutineScope) : PersistentStateComponent<QProfileState>, Disposable {

Check warning on line 46 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QRegionProfileManager.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused symbol

Property "cs" is never used

// 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 +69,7 @@
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 +108,22 @@
}
}

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

val future = CompletableFuture.supplyAsync {
listRegionProfiles(project)
}.whenComplete { t, u ->
// This runs when the future completes (success or failure)
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