Skip to content

Commit e5c6e2a

Browse files
Aydar Mukhametzyanovintellij-monorepo-bot
authored andcommitted
IJPL-198927 Search Everywhere: release the first throttled batch w/o delay if all essential providers sent >= 15 results
GitOrigin-RevId: 0e31f23a58f6156124db92fc3d85a3a780463084
1 parent b533573 commit e5c6e2a

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

  • platform/searchEverywhere/frontend/src/vm

platform/searchEverywhere/frontend/src/vm/SeTabVm.kt

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.lang.Language
1212
import com.intellij.openapi.actionSystem.AnActionEvent
1313
import com.intellij.openapi.actionSystem.DataContext
1414
import com.intellij.openapi.application.EDT
15+
import com.intellij.openapi.options.advanced.AdvancedSettings
1516
import com.intellij.openapi.project.DumbService
1617
import com.intellij.openapi.project.Project
1718
import com.intellij.openapi.util.Disposer
@@ -190,25 +191,43 @@ class SeTabVm(
190191

191192
private const val ESSENTIALS_WAITING_TIMEOUT: Long = 2000
192193
private const val ESSENTIALS_THROTTLE_DELAY: Long = 100
194+
private const val ESSENTIALS_ENOUGH_COUNT: Int = 15
193195

194196
private fun Flow<SeResultEvent>.throttleUntilEssentialsArrive(essentialProviderIds: Set<SeProviderId>): Flow<ThrottledItems<SeResultEvent>> {
195-
val nonArrivedEssentialProviders = essentialProviderIds.toMutableSet()
197+
val essentialProvidersCounts = essentialProviderIds.associateWith { 0 }.toMutableMap()
196198

197199
SeLog.log(SeLog.THROTTLING) { "Will start throttle with essential providers: $essentialProviderIds"}
198200
return throttledWithAccumulation(ESSENTIALS_WAITING_TIMEOUT, { it !is SeResultEndEvent }) { event, size ->
199-
val idToRemove = when (event) {
200-
is SeResultAddedEvent -> event.itemData.providerId
201-
is SeResultReplacedEvent -> event.newItemData.providerId
202-
is SeResultEndEvent -> event.providerId
203-
}
201+
val providerId = event.providerId()
204202

205-
if (nonArrivedEssentialProviders.remove(idToRemove)) {
206-
SeLog.log(SeLog.THROTTLING) { "Arrived: $idToRemove" }
203+
when (event) {
204+
is SeResultEndEvent -> {
205+
if (essentialProvidersCounts.remove(providerId) != null) {
206+
SeLog.log(SeLog.THROTTLING) { "Ended: $providerId" }
207+
}
208+
}
209+
else -> {
210+
essentialProvidersCounts[providerId]?.let {
211+
SeLog.log(SeLog.THROTTLING) { "Arrived: $providerId ($it)" }
212+
essentialProvidersCounts[providerId] = it + 1
213+
}
214+
}
207215
}
208216

209-
return@throttledWithAccumulation if (nonArrivedEssentialProviders.isEmpty()) ESSENTIALS_THROTTLE_DELAY else null
217+
return@throttledWithAccumulation (
218+
if (essentialProvidersCounts.isEmpty()) 0
219+
else if (essentialProvidersCounts.values.all { it >= ESSENTIALS_ENOUGH_COUNT }) 0
220+
else if (essentialProvidersCounts.values.all { it > 0 }) ESSENTIALS_THROTTLE_DELAY
221+
else null
222+
)
210223
}
211224
}
212225

226+
private fun SeResultEvent.providerId() = when (this) {
227+
is SeResultAddedEvent -> itemData.providerId
228+
is SeResultReplacedEvent -> newItemData.providerId
229+
is SeResultEndEvent -> providerId
230+
}
231+
213232
@ApiStatus.Internal
214233
class SeSearchContext(val searchId: String, val tabId: String, val searchPattern: String, val resultsFlow: Flow<ThrottledItems<SeResultEvent>>)

0 commit comments

Comments
 (0)