From 5b5ba97bb20ce9c92599d77e2005b07ba94ffdcc Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sun, 2 Feb 2025 11:01:23 -0600 Subject: [PATCH] Limit chip updates --- .../main/java/org/tasks/ui/ChipListCache.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/tasks/ui/ChipListCache.kt b/app/src/main/java/org/tasks/ui/ChipListCache.kt index c6972ddd6..df23a5f60 100644 --- a/app/src/main/java/org/tasks/ui/ChipListCache.kt +++ b/app/src/main/java/org/tasks/ui/ChipListCache.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.tasks.LocalBroadcastManager +import org.tasks.compose.throttleLatest import org.tasks.data.dao.CaldavDao import org.tasks.data.dao.TagDataDao import org.tasks.data.entity.CaldavAccount @@ -45,6 +46,7 @@ class ChipListCache @Inject internal constructor( } private fun updateTags(updated: List) { + Timber.d("Updating tags") tagDatas.clear() for (update in updated) { tagDatas[update.remoteId] = TagFilter(update) @@ -57,12 +59,16 @@ class ChipListCache @Inject internal constructor( fun getTag(tag: String?): TagFilter? = tagDatas[tag] init { - caldavDao - .watchAccounts() - .combine(caldavDao.subscribeToCalendars()) { accounts, calendars -> - updateCaldavCalendars(accounts, calendars) - } + combine(caldavDao.watchAccounts(), caldavDao.subscribeToCalendars()) { accounts, calendars -> + accounts to calendars + } + .throttleLatest(1000) + .onEach { (accounts, calendars) -> updateCaldavCalendars(accounts, calendars) } + .launchIn(scope) + tagDataDao + .subscribeToTags() + .throttleLatest(1000) + .onEach { updateTags(it) } .launchIn(scope) - tagDataDao.subscribeToTags().onEach { updateTags(it) }.launchIn(scope) } } \ No newline at end of file