From 5fc984e1bcb394909de88e3c2b569308f6abeeb5 Mon Sep 17 00:00:00 2001 From: Vera Petrenkova Date: Mon, 1 Sep 2025 18:04:52 +0200 Subject: [PATCH] [find in files] IJPL-205277 add buffer to improve performance and responsiveness GitOrigin-RevId: e0f3446c9b0b26774de82af695877f49e5b8eb60 --- platform/find/src/FindAndReplaceExecutorImpl.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/find/src/FindAndReplaceExecutorImpl.kt b/platform/find/src/FindAndReplaceExecutorImpl.kt index be8ed42b7daf..26ed815e6376 100644 --- a/platform/find/src/FindAndReplaceExecutorImpl.kt +++ b/platform/find/src/FindAndReplaceExecutorImpl.kt @@ -31,6 +31,7 @@ import fleet.rpc.client.RpcTimeoutException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.take import kotlinx.coroutines.launch @@ -86,10 +87,13 @@ open class FindAndReplaceExecutorImpl(val coroutineScope: CoroutineScope) : Find projectId = project.projectId(), filesToScanInitially = filesToScanInitially.map { it.rpcId() }, maxUsagesCount = maxUsagesCount - ).let { - if (shouldThrottle) it.throttledWithAccumulation() - else it.map { event -> ThrottledOneItem(event) } - }.take(maxUsagesCount).collect { throttledItems -> + ).take(maxUsagesCount) + .buffer(capacity = maxUsagesCount) + .let { + if (shouldThrottle) it.throttledWithAccumulation() + else it.map { event -> ThrottledOneItem(event) } + } + .collect { throttledItems -> if (searchDisposable?.isDisposed == true) { return@collect }