From 24ef184de51797cec99e0eb9fa1348196ddce17d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 12 Jun 2026 17:22:57 +0000 Subject: [PATCH] fix: start the app recommendations flow eagerly to pin notes in the soft cache With WhileSubscribed, nothing held a strong reference to my own 31989 notes while no UI was collecting; under memory pressure the soft cache could drop them, and the next recommendApp would rebuild that kind's event from an empty snapshot, wiping previously recommended apps. Eagerly keeps the observer registered (its result set strongly references the notes), matching the sibling account states. https://claude.ai/code/session_015dX5vWqvXUYD8rzPYX8vTB --- .../model/nip89AppHandlers/AppRecommendationsState.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip89AppHandlers/AppRecommendationsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip89AppHandlers/AppRecommendationsState.kt index d2e5879e5f..f341af4e10 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip89AppHandlers/AppRecommendationsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip89AppHandlers/AppRecommendationsState.kt @@ -64,13 +64,19 @@ class AppRecommendationsState( * My kind 31989 recommendation events (one per handled kind), kept in * sync as the cache consumes new versions. UI should collect this * instead of rescanning the cache on every event bundle. + * + * Eagerly started on purpose, like the sibling account states: the + * registered observer holds strong references to these notes, pinning + * them in the soft-reference cache so the read-modify-write publishers + * below never rebuild a 31989 from a partially garbage-collected + * snapshot (which would silently drop previously recommended apps). */ val flow: StateFlow> = cache .observeEvents( Filter(kinds = listOf(AppRecommendationEvent.KIND), authors = listOf(signer.pubKey)), ).flowOn(Dispatchers.IO) - .stateIn(scope, SharingStarted.WhileSubscribed(30000), existingRecommendationEvents()) + .stateIn(scope, SharingStarted.Eagerly, existingRecommendationEvents()) /** * Serializes read-modify-write of the per-kind recommendation events so