Performance: Avoids saving the first collection on login

This commit is contained in:
Vitor Pamplona
2025-04-01 18:51:29 -04:00
parent 09024fbc61
commit 7e3f64fc61
2 changed files with 5 additions and 3 deletions
@@ -122,13 +122,13 @@ class AccountSettings(
var hasDonatedInVersion: MutableStateFlow<Set<String>> = MutableStateFlow(setOf<String>()), var hasDonatedInVersion: MutableStateFlow<Set<String>> = MutableStateFlow(setOf<String>()),
val pendingAttestations: MutableStateFlow<Map<HexKey, String>> = MutableStateFlow<Map<HexKey, String>>(mapOf()), val pendingAttestations: MutableStateFlow<Map<HexKey, String>> = MutableStateFlow<Map<HexKey, String>>(mapOf()),
) { ) {
val saveable = MutableStateFlow(AccountSettingsUpdater(this)) val saveable = MutableStateFlow(AccountSettingsUpdater(null))
val syncedSettings: AccountSyncedSettings = val syncedSettings: AccountSyncedSettings =
backupSyncedSettings?.let { AccountSyncedSettings(it) } backupSyncedSettings?.let { AccountSyncedSettings(it) }
?: AccountSyncedSettings(AccountSyncedSettingsInternal()) ?: AccountSyncedSettings(AccountSyncedSettingsInternal())
class AccountSettingsUpdater( class AccountSettingsUpdater(
val accountSettings: AccountSettings, val accountSettings: AccountSettings?,
) )
fun saveAccountSettings() { fun saveAccountSettings() {
@@ -179,7 +179,9 @@ class AccountStateViewModel : ViewModel() {
collectorJob = collectorJob =
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
accountSettings.saveable.debounce(1000).collect { accountSettings.saveable.debounce(1000).collect {
LocalPreferences.saveToEncryptedStorage(it.accountSettings) if (it.accountSettings != null) {
LocalPreferences.saveToEncryptedStorage(it.accountSettings)
}
} }
} }
} }