From fc96d89a446ccb32f2ab21340e1f4b2ec43670eb Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 11 Jun 2024 15:05:57 -0400 Subject: [PATCH] Reducing double launch or co-routines --- .../amethyst/service/NostrDataSource.kt | 12 +++++------- .../amethyst/ui/screen/FeedViewModel.kt | 12 +++++------- .../amethyst/ui/screen/StringFeedViewModel.kt | 10 ++++------ .../amethyst/ui/screen/UserFeedViewModel.kt | 10 ++++------ 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt index 501ee95af..4b6beb515 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt @@ -194,14 +194,12 @@ abstract class NostrDataSource(val debugName: String) { private val bundler = BundledUpdate(300, Dispatchers.IO) fun invalidateFilters() { - scope.launch(Dispatchers.IO) { - bundler.invalidate { - // println("DataSource: ${this.javaClass.simpleName} InvalidateFilters") + bundler.invalidate { + // println("DataSource: ${this.javaClass.simpleName} InvalidateFilters") - // adds the time to perform the refresh into this delay - // holding off new updates in case of heavy refresh routines. - resetFiltersSuspend() - } + // adds the time to perform the refresh into this delay + // holding off new updates in case of heavy refresh routines. + resetFiltersSuspend() } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index 7685b2746..c4ca09313 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -436,13 +436,11 @@ abstract class FeedViewModel(val localFilter: FeedFilter) : fun checkKeysInvalidateDataAndSendToTop() { if (lastFeedKey != localFilter.feedKey()) { - viewModelScope.launch(Dispatchers.IO) { - bundler.invalidate(false) { - // adds the time to perform the refresh into this delay - // holding off new updates in case of heavy refresh routines. - refreshSuspended() - sendToTop() - } + bundler.invalidate(false) { + // adds the time to perform the refresh into this delay + // holding off new updates in case of heavy refresh routines. + refreshSuspended() + sendToTop() } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedViewModel.kt index 7db649be8..438c5849b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/StringFeedViewModel.kt @@ -95,12 +95,10 @@ open class StringFeedViewModel(val dataSource: FeedFilter) : private val bundler = BundledUpdate(250, Dispatchers.IO) override fun invalidateData(ignoreIfDoing: Boolean) { - viewModelScope.launch(Dispatchers.IO) { - bundler.invalidate(ignoreIfDoing) { - // adds the time to perform the refresh into this delay - // holding off new updates in case of heavy refresh routines. - refreshSuspended() - } + bundler.invalidate(ignoreIfDoing) { + // adds the time to perform the refresh into this delay + // holding off new updates in case of heavy refresh routines. + refreshSuspended() } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt index 4804b3cb9..58a5b8b4e 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt @@ -126,12 +126,10 @@ open class UserFeedViewModel(val dataSource: FeedFilter) : private val bundler = BundledUpdate(250, Dispatchers.IO) override fun invalidateData(ignoreIfDoing: Boolean) { - viewModelScope.launch(Dispatchers.IO) { - bundler.invalidate(ignoreIfDoing) { - // adds the time to perform the refresh into this delay - // holding off new updates in case of heavy refresh routines. - refreshSuspended() - } + bundler.invalidate(ignoreIfDoing) { + // adds the time to perform the refresh into this delay + // holding off new updates in case of heavy refresh routines. + refreshSuspended() } }