perf(pipeline): remove fixed reindex delay and main-thread file snapshot
The reindex pipeline slept for a fixed second after waiting for indexing to finish, even though the wait already blocks until the index is ready, and it listed the dictionary directory on the main thread. Drop the redundant sleep and take the directory snapshot on the IO dispatcher so the pipeline no longer stalls the UI thread.
This commit is contained in:
1 parent
ec32b84ac9
commit
27f77f2eba
1 file changed
+3
-4
+3
-4
@@ -8,11 +8,9 @@ import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class DictionaryPipelineCoordinator(
|
||||
private val scope: CoroutineScope,
|
||||
@@ -62,7 +60,9 @@ class DictionaryPipelineCoordinator(
|
||||
pipelineJob?.cancel()
|
||||
pipelineJob = scope.launch(launchDispatcher) {
|
||||
val dir = File(dictionaryPath())
|
||||
val filesBeforeReindex = dir.listFiles()?.map { it.name }?.toSet() ?: emptySet()
|
||||
val filesBeforeReindex = withContext(ioDispatcher) {
|
||||
dir.listFiles()?.map { it.name }?.toSet() ?: emptySet()
|
||||
}
|
||||
try {
|
||||
triggerReindexing(isImport)
|
||||
if (isImport) {
|
||||
@@ -95,7 +95,6 @@ class DictionaryPipelineCoordinator(
|
||||
|
||||
private suspend fun triggerReindexing(isImport: Boolean) = withContext(ioDispatcher) {
|
||||
steps.waitForIndexingCompletion()
|
||||
delay(1.seconds)
|
||||
|
||||
val path = dictionaryPath()
|
||||
if (isImport) {
|
||||
|
||||
Reference in new issue
Block a user