Throttle Wikipedia requests

This commit is contained in:
MM20 2023-04-13 20:28:55 +02:00
parent 21a5501a75
commit 09b856e71c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -39,6 +39,7 @@ import de.mm20.launcher2.wikipedia.WikipediaRepository
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.channelFlow
@ -194,6 +195,7 @@ internal class SearchServiceImpl(
} }
if (wikipedia.enabled) { if (wikipedia.enabled) {
launch { launch {
delay(750)
wikipediaRepository.search(query, loadImages = wikipedia.images) wikipediaRepository.search(query, loadImages = wikipedia.images)
.map { it?.let { listOf(it) } ?: listOf() } .map { it?.let { listOf(it) } ?: listOf() }
.withCustomLabels(customAttributesRepository) .withCustomLabels(customAttributesRepository)