diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 663580333..f56a0e059 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -1548,32 +1548,47 @@ class AccountViewModel( val accountViewModel: AccountViewModel, ) : GenericBaseCache(20) { override suspend fun compute(key: String): LoadedBechLink? = - Nip19Bech32.uriToRoute(key)?.let { - var returningNote: Note? = null + withContext(Dispatchers.Default) { + Nip19Bech32.uriToRoute(key)?.let { + var returningNote: Note? = null - when (val parsed = it.entity) { - is Nip19Bech32.NSec -> {} - is Nip19Bech32.NPub -> {} - is Nip19Bech32.NProfile -> {} - is Nip19Bech32.Note -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } } - is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } } - is Nip19Bech32.NEmbed -> - withContext(Dispatchers.Default) { - val baseNote = LocalCache.getOrCreateNote(parsed.event) - if (baseNote.event == null) { - launch(Dispatchers.IO) { - LocalCache.verifyAndConsume(parsed.event, null) + when (val parsed = it.entity) { + is Nip19Bech32.NSec -> {} + is Nip19Bech32.NPub -> {} + is Nip19Bech32.NProfile -> {} + is Nip19Bech32.Note -> { + LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> + returningNote = note + } + } + is Nip19Bech32.NEvent -> { + LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> + returningNote = note + } + } + is Nip19Bech32.NEmbed -> + withContext(Dispatchers.Default) { + val baseNote = LocalCache.getOrCreateNote(parsed.event) + if (baseNote.event == null) { + launch(Dispatchers.Default) { + LocalCache.verifyAndConsume(parsed.event, null) + } } + + returningNote = baseNote } - returningNote = baseNote + is Nip19Bech32.NRelay -> {} + is Nip19Bech32.NAddress -> { + LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note -> + returningNote = note + } } - is Nip19Bech32.NRelay -> {} - is Nip19Bech32.NAddress -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note -> returningNote = note } } - else -> {} - } + else -> {} + } - LoadedBechLink(returningNote, it) + LoadedBechLink(returningNote, it) + } } } } diff --git a/commons/src/main/java/com/vitorpamplona/amethyst/commons/compose/CachedState.kt b/commons/src/main/java/com/vitorpamplona/amethyst/commons/compose/CachedState.kt index 3cc746608..f8ae3a298 100644 --- a/commons/src/main/java/com/vitorpamplona/amethyst/commons/compose/CachedState.kt +++ b/commons/src/main/java/com/vitorpamplona/amethyst/commons/compose/CachedState.kt @@ -31,7 +31,10 @@ fun produceCachedState( key: K, ): State = produceState(initialValue = cache.cached(key), key1 = key) { - value = cache.update(key) + val newValue = cache.update(key) + if (value != newValue) { + value = newValue + } } @Composable @@ -41,7 +44,10 @@ fun produceCachedState( updateValue: K, ): State = produceState(initialValue = cache.cached(updateValue), key1 = key) { - value = cache.update(updateValue) + val newValue = cache.update(updateValue) + if (value != newValue) { + value = newValue + } } interface CachedState {