From 7212cad052a1f715d5ca5a7d84a6c75e82c16903 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Tue, 21 Apr 2026 23:29:58 +0200 Subject: [PATCH] Limit search to only 1 relay. --- .../kotlin/ac/aux/compose/database/dao/NostrDao.kt | 7 ++++++- .../src/commonMain/kotlin/ac/aux/compose/nostr/Relays.kt | 2 +- .../ac/aux/compose/ui/view/model/FeedListViewModel.kt | 2 +- .../compose/ui/view/model/MetadataEventDetailViewModel.kt | 2 +- .../ac/aux/compose/ui/view/model/NavigationViewModel.kt | 4 ++-- .../aux/compose/ui/view/model/NostrEventDetailViewModel.kt | 2 +- .../ac/aux/compose/ui/view/model/SearchResultViewModel.kt | 2 +- .../view/model/UnqueuedProfileSynchronizationViewModel.kt | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt index a9de3d82..bfc48507 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt @@ -16,6 +16,7 @@ import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent +import kotlin.math.log import kotlin.time.Clock import kotlin.time.Instant @@ -92,8 +93,12 @@ abstract class NostrDao( // Add new nostr event database.nostrEventDao().insert(nostrEvent) } else if (nostrEvent.createdAt > storedNostrEvent.createdAt) { - // Update nostr event + // Update nostr event` database.nostrEventDao().upsert(nostrEvent) + } else { + // Nothing else needs to be done + logger.i("We have the latest version for: ${nostrEvent.id}") + return } // Index nostrEvent diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/nostr/Relays.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/nostr/Relays.kt index 967a607a..53b210c5 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/nostr/Relays.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/nostr/Relays.kt @@ -34,7 +34,7 @@ object Relays { val nostr1 = RelayUrlNormalizer.normalize("wss://profiles.nostr1.com") val bootstrapInboxRelaySet = setOf(damus, primal, mom, nos, bitcoiner, oxtr, yabu) - val eventFinderRelaySet = setOf(wine, damus, primal, mom, nos, bitcoiner, oxtr) + val eventFinderRelaySet = setOf(primal, wine, damus, mom, nos, bitcoiner, oxtr) val eventPublishRelaySet = setOf(primal, mom, nos, bitcoiner, oxtr) diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/FeedListViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/FeedListViewModel.kt index ab47415d..c1ffbaac 100755 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/FeedListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/FeedListViewModel.kt @@ -73,7 +73,7 @@ class FeedListViewModel( viewModelScope.launch(Dispatchers.IO) { // Sync Notifications... might want to also run this in the background nostrRepository.queueSynchronizeNostrEvent( - Relays.eventPublishRelaySet.map { normalizedRelay -> + Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays... SynchronizeNostrEventRequest( purpose = "feed", synchronizationFilters = arrayOf( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/MetadataEventDetailViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/MetadataEventDetailViewModel.kt index fda057a1..056025f4 100755 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/MetadataEventDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/MetadataEventDetailViewModel.kt @@ -207,7 +207,7 @@ class MetadataEventDetailViewModel( viewModelScope.launch(Dispatchers.IO) { // Sync Notifications... might want to also run this in the background nostrRepository.queueSynchronizeNostrEvent( - Relays.eventFinderRelaySet.map { normalizedRelay -> + Relays.eventFinderRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all relays instead of 1 SynchronizeNostrEventRequest( purpose = "search", synchronizationFilters = arrayOf( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt index 8e89db13..5e22faf1 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt @@ -164,7 +164,7 @@ class NavigationViewModel( nostrRepository.saveNostrEvent( nostrEvent = it, synchronizeNostrEventRequest, - synchronizationRelayURLs = Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url } + synchronizeNostrEventRequest.relayURL + synchronizationRelayURLs = listOf(synchronizeNostrEventRequest.relayURL) // TODO: + Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url } ) } @@ -176,7 +176,7 @@ class NavigationViewModel( nostrRepository.saveNostrEvent( nostrEvent = nostrEvent, synchronizeNostrEventRequest, - synchronizationRelayURLs = Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url } + synchronizeNostrEventRequest.relayURL + synchronizationRelayURLs = listOf(synchronizeNostrEventRequest.relayURL) // TODO: + Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url } ) } } diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NostrEventDetailViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NostrEventDetailViewModel.kt index 07f66803..3abe1b40 100755 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NostrEventDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NostrEventDetailViewModel.kt @@ -42,7 +42,7 @@ class NostrEventDetailViewModel( viewModelScope.launch(Dispatchers.IO) { // Sync Notifications... might want to also run this in the background nostrRepository.queueSynchronizeNostrEvent( - Relays.eventPublishRelaySet.map { normalizedRelay -> + Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all relays instead of 1 SynchronizeNostrEventRequest( purpose = "detail", synchronizationFilters = arrayOf( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/SearchResultViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/SearchResultViewModel.kt index 13edf8c2..c1febc43 100755 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/SearchResultViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/SearchResultViewModel.kt @@ -128,7 +128,7 @@ class SearchResultViewModel( viewModelScope.launch(Dispatchers.IO) { // Sync Notifications... might want to also run this in the background searchRepository.submitSearch( - Relays.eventFinderRelaySet.map { normalizedRelay -> + Relays.eventFinderRelaySet.take(1).map { normalizedRelay -> // TODO: Search all relays instead of the first SynchronizeNostrEventRequest( purpose = "search", synchronizationFilters = arrayOf( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/UnqueuedProfileSynchronizationViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/UnqueuedProfileSynchronizationViewModel.kt index 0c3ab10c..c77288b4 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/UnqueuedProfileSynchronizationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/UnqueuedProfileSynchronizationViewModel.kt @@ -53,7 +53,7 @@ class UnqueuedProfileSynchronizationViewModel( delay(2_000) nostrRepository.queueSynchronizeNostrEvent( - Relays.eventPublishRelaySet.map { normalizedRelayUrl -> + Relays.eventPublishRelaySet.take(1).map { normalizedRelayUrl -> // TODO: Sync from all relays instead of 1 SynchronizeNostrEventRequest( purpose = "sign-in", synchronizationFilters = arrayOf(