From d8278002e7bb86070b4cd937a4b9c937903cae49 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 3 Jun 2026 14:47:41 +0700 Subject: [PATCH 1/2] fix crash when get all cached metadata --- shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt index 8bccc85..868013d 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -505,13 +505,18 @@ class Nostr { val results = mutableMapOf() events?.toVec()?.forEach { event -> - val metadata = Metadata.fromJson(event.content()) - results[event.author()] = metadata + try { + val metadata = Metadata.fromJson(event.content()) + results[event.author()] = metadata + } catch (e: Exception) { + println("Failed to parse metadata: $e") + } } return results } catch (e: Exception) { - throw IllegalStateException("Failed to get cache metadata: ${e.message}", e) + println("Failed to get all cache metadata: ${e.message}") + return emptyMap() } } -- 2.49.1 From 026b6f0fa2e690444c540a4e145d5a4ff5779f16 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 3 Jun 2026 14:49:37 +0700 Subject: [PATCH 2/2] clean up --- shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt | 2 +- .../src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt index 868013d..bbf83f7 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -500,7 +500,7 @@ class Nostr { suspend fun getAllCacheMetadata(): Map { try { - val filter = Filter().kind(Kind.fromStd(KindStandard.METADATA)).limit(200u) + val filter = Filter().kind(Kind.fromStd(KindStandard.METADATA)).limit(100u) val events = client?.database()?.query(filter) val results = mutableMapOf() diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 751ab71..62007e2 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -34,6 +34,7 @@ import rust.nostr.sdk.UnsignedEvent import su.reya.coop.blossom.BlossomClient import su.reya.coop.storage.SecretStorage import kotlin.time.Clock +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds class NostrViewModel( @@ -177,7 +178,7 @@ class NostrViewModel( val lastFlushTime = Clock.System.now().toEpochMilliseconds() while (batch.isNotEmpty()) { - val nextKey = withTimeoutOrNull(timeout) { + val nextKey = withTimeoutOrNull(timeout.milliseconds) { metadataRequestChannel.receive() } @@ -255,7 +256,7 @@ class NostrViewModel( nostr.getUserMetadata() // Small delay to ensure all relays are connected - delay(3000) + delay(3000.milliseconds) // Check if the relay list is empty val relays = nostr.getMsgRelays(pubkey) @@ -266,7 +267,7 @@ class NostrViewModel( break } - delay(500) + delay(500.milliseconds) } } } -- 2.49.1