Don't apply limits for negentropy...
This commit is contained in:
1 parent
17def682e0
commit
cd17e69c07
4 files changed
+72
-24
No files matched your search
+21
-12
@@ -66,47 +66,56 @@ interface NostrEventDao {
|
|||||||
): Flow<List<LocalNostrEvent>>
|
): Flow<List<LocalNostrEvent>>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getNostrEvents(kinds: Array<Kind>, since: Instant = GENESIS_AT): List<NostrEvent>
|
fun getNostrEvents(
|
||||||
|
kinds: Array<Kind>,
|
||||||
|
since: Instant = GENESIS_AT,
|
||||||
|
limit: Int
|
||||||
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE content LIKE '%' || :search || '%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE content LIKE '%' || :search || '%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getFilteredNostrEvents(
|
fun getFilteredNostrEvents(
|
||||||
kinds: Array<Kind>,
|
kinds: Array<Kind>,
|
||||||
search: String,
|
search: String,
|
||||||
since: Instant = GENESIS_AT
|
since: Instant = GENESIS_AT,
|
||||||
|
limit: Int
|
||||||
): List<NostrEvent>
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND id in (:ids) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND id in (:ids) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getFilteredNostrEvents(
|
fun getFilteredNostrEvents(
|
||||||
kinds: Array<Kind>,
|
kinds: Array<Kind>,
|
||||||
ids: Array<HexKey>,
|
ids: Array<HexKey>,
|
||||||
since: Instant = GENESIS_AT
|
since: Instant = GENESIS_AT,
|
||||||
|
limit: Int
|
||||||
): List<NostrEvent>
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND pubKey in (:authors) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND pubKey in (:authors) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getAuthoredNostrEvents(
|
fun getAuthoredNostrEvents(
|
||||||
kinds: Array<Kind>,
|
kinds: Array<Kind>,
|
||||||
authors: Array<HexKey>,
|
authors: Array<HexKey>,
|
||||||
since: Instant = GENESIS_AT
|
since: Instant = GENESIS_AT,
|
||||||
|
limit: Int
|
||||||
): List<NostrEvent>
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :publicKey || '%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :publicKey || '%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getPublicKeyMentionedNostrEvents(
|
fun getPublicKeyMentionedNostrEvents(
|
||||||
kinds: Array<Kind>,
|
kinds: Array<Kind>,
|
||||||
publicKey: HexKey,
|
publicKey: HexKey,
|
||||||
since: Instant = GENESIS_AT
|
since: Instant = GENESIS_AT,
|
||||||
|
limit: Int
|
||||||
): List<NostrEvent>
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :eventId || '%reply%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC")
|
@Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :eventId || '%reply%' AND kind in (:kinds) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||||
fun getNostrEventReplies(
|
fun getNostrEventReplies(
|
||||||
kinds: Array<Kind>,
|
kinds: Array<Kind>,
|
||||||
eventId: HexKey,
|
eventId: HexKey,
|
||||||
since: Instant
|
since: Instant,
|
||||||
|
limit: Int
|
||||||
): List<NostrEvent>
|
): List<NostrEvent>
|
||||||
|
|
||||||
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY savedAt DESC")
|
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY savedAt DESC")
|
||||||
|
|||||||
+40
-8
@@ -7,7 +7,6 @@ import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest
|
|||||||
import ac.cord.auxiliary.compose.database.model.Connection
|
import ac.cord.auxiliary.compose.database.model.Connection
|
||||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||||
import ac.cord.auxiliary.compose.database.model.NostrEvent
|
import ac.cord.auxiliary.compose.database.model.NostrEvent
|
||||||
import ac.cord.auxiliary.compose.database.model.NostrEventRelay
|
|
||||||
import ac.cord.auxiliary.compose.database.model.Profile
|
import ac.cord.auxiliary.compose.database.model.Profile
|
||||||
import ac.cord.auxiliary.compose.database.model.RecentSearch
|
import ac.cord.auxiliary.compose.database.model.RecentSearch
|
||||||
import ac.cord.auxiliary.compose.database.model.Relay
|
import ac.cord.auxiliary.compose.database.model.Relay
|
||||||
@@ -558,7 +557,10 @@ class DatabaseNostrRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getNostrFeedIds(synchronizationFilters: Array<SynchronizationFilter>): List<NostrEvent> {
|
override suspend fun getNostrFeedIds(
|
||||||
|
synchronizationFilters: Array<SynchronizationFilter>,
|
||||||
|
applyLimits: Boolean
|
||||||
|
): List<NostrEvent> {
|
||||||
if (synchronizationFilters.size == 1) {
|
if (synchronizationFilters.size == 1) {
|
||||||
val synchronizationFilter = synchronizationFilters.first()
|
val synchronizationFilter = synchronizationFilters.first()
|
||||||
|
|
||||||
@@ -567,21 +569,36 @@ class DatabaseNostrRepository(
|
|||||||
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
||||||
database.nostrEventDao().getFilteredNostrEvents(
|
database.nostrEventDao().getFilteredNostrEvents(
|
||||||
kinds = synchronizationFilter.kinds,
|
kinds = synchronizationFilter.kinds,
|
||||||
search = synchronizationFilter.search
|
search = synchronizationFilter.search,
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
synchronizationFilter.kinds != null && synchronizationFilter.ids != null -> {
|
synchronizationFilter.kinds != null && synchronizationFilter.ids != null -> {
|
||||||
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
||||||
database.nostrEventDao().getFilteredNostrEvents(
|
database.nostrEventDao().getFilteredNostrEvents(
|
||||||
kinds = synchronizationFilter.kinds,
|
kinds = synchronizationFilter.kinds,
|
||||||
ids = synchronizationFilter.ids
|
ids = synchronizationFilter.ids,
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
synchronizationFilter.kinds != null && synchronizationFilter.authors != null -> {
|
synchronizationFilter.kinds != null && synchronizationFilter.authors != null -> {
|
||||||
logger.d("observeAuthoredNostrEvents: $synchronizationFilter")
|
logger.d("observeAuthoredNostrEvents: $synchronizationFilter")
|
||||||
database.nostrEventDao().getAuthoredNostrEvents(
|
database.nostrEventDao().getAuthoredNostrEvents(
|
||||||
kinds = synchronizationFilter.kinds,
|
kinds = synchronizationFilter.kinds,
|
||||||
authors = synchronizationFilter.authors
|
authors = synchronizationFilter.authors,
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
synchronizationFilter.kinds != null && synchronizationFilter.since != null && synchronizationFilter.tags?.contains("e") == true && synchronizationFilter.tags["e"]?.first()?.isNotEmpty() == true -> {
|
synchronizationFilter.kinds != null && synchronizationFilter.since != null && synchronizationFilter.tags?.contains("e") == true && synchronizationFilter.tags["e"]?.first()?.isNotEmpty() == true -> {
|
||||||
@@ -589,14 +606,24 @@ class DatabaseNostrRepository(
|
|||||||
database.nostrEventDao().getNostrEventReplies(
|
database.nostrEventDao().getNostrEventReplies(
|
||||||
kinds = synchronizationFilter.kinds,
|
kinds = synchronizationFilter.kinds,
|
||||||
eventId = synchronizationFilter.tags["e"]?.first()!!,
|
eventId = synchronizationFilter.tags["e"]?.first()!!,
|
||||||
since = synchronizationFilter.since
|
since = synchronizationFilter.since,
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
synchronizationFilter.kinds != null && synchronizationFilter.tags?.contains("p") == true && synchronizationFilter.tags["p"]?.first()?.isNotEmpty() == true -> {
|
synchronizationFilter.kinds != null && synchronizationFilter.tags?.contains("p") == true && synchronizationFilter.tags["p"]?.first()?.isNotEmpty() == true -> {
|
||||||
logger.d("observePublicKeyMentionedNostrEvents: $synchronizationFilter")
|
logger.d("observePublicKeyMentionedNostrEvents: $synchronizationFilter")
|
||||||
database.nostrEventDao().getPublicKeyMentionedNostrEvents(
|
database.nostrEventDao().getPublicKeyMentionedNostrEvents(
|
||||||
kinds = synchronizationFilter.kinds,
|
kinds = synchronizationFilter.kinds,
|
||||||
publicKey = synchronizationFilter.tags["p"]?.first()!!
|
publicKey = synchronizationFilter.tags["p"]?.first()!!,
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@@ -604,7 +631,12 @@ class DatabaseNostrRepository(
|
|||||||
database.nostrEventDao().getNostrEvents(
|
database.nostrEventDao().getNostrEvents(
|
||||||
kinds = arrayOf(
|
kinds = arrayOf(
|
||||||
TextNoteEvent.KIND,
|
TextNoteEvent.KIND,
|
||||||
)
|
),
|
||||||
|
limit = if (applyLimits) {
|
||||||
|
synchronizationFilter.limit ?: 50
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -107,7 +107,10 @@ interface NostrRepository {
|
|||||||
|
|
||||||
suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent>>
|
suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent>>
|
||||||
|
|
||||||
suspend fun getNostrFeedIds(synchronizationFilters: Array<SynchronizationFilter>): List<NostrEvent>
|
suspend fun getNostrFeedIds(
|
||||||
|
synchronizationFilters: Array<SynchronizationFilter>,
|
||||||
|
applyLimits: Boolean = true
|
||||||
|
): List<NostrEvent>
|
||||||
|
|
||||||
suspend fun observeLocalNostrEventById(nostrEventId: String): Flow<LocalNostrEvent?>
|
suspend fun observeLocalNostrEventById(nostrEventId: String): Flow<LocalNostrEvent?>
|
||||||
|
|
||||||
@@ -259,7 +262,10 @@ interface NostrRepository {
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getNostrFeedIds(synchronizationFilters: Array<SynchronizationFilter>): List<NostrEvent> {
|
override suspend fun getNostrFeedIds(
|
||||||
|
synchronizationFilters: Array<SynchronizationFilter>,
|
||||||
|
applyLimits: Boolean
|
||||||
|
): List<NostrEvent> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -226,7 +226,8 @@ class NavigationViewModel(
|
|||||||
val events = nostrRepository.getNostrFeedIds(
|
val events = nostrRepository.getNostrFeedIds(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
negentropySynchronizeRequest.synchronizationFilter
|
negentropySynchronizeRequest.synchronizationFilter
|
||||||
)
|
),
|
||||||
|
applyLimits = false
|
||||||
)
|
)
|
||||||
logger.d("Events: ${events.size}")
|
logger.d("Events: ${events.size}")
|
||||||
val storage = StorageVector().apply {
|
val storage = StorageVector().apply {
|
||||||
@@ -253,7 +254,7 @@ class NavigationViewModel(
|
|||||||
tagsAll = negentropySynchronizeRequest.synchronizationFilter.tagsAll,
|
tagsAll = negentropySynchronizeRequest.synchronizationFilter.tagsAll,
|
||||||
since = negentropySynchronizeRequest.synchronizationFilter.since?.epochSeconds,
|
since = negentropySynchronizeRequest.synchronizationFilter.since?.epochSeconds,
|
||||||
until = negentropySynchronizeRequest.synchronizationFilter.until?.epochSeconds,
|
until = negentropySynchronizeRequest.synchronizationFilter.until?.epochSeconds,
|
||||||
limit = negentropySynchronizeRequest.synchronizationFilter.limit,
|
limit = null, // We don't do limits when performing negentropy...
|
||||||
search = negentropySynchronizeRequest.synchronizationFilter.search
|
search = negentropySynchronizeRequest.synchronizationFilter.search
|
||||||
),
|
),
|
||||||
initialMessage = negentropy.initiate().toHexString()
|
initialMessage = negentropy.initiate().toHexString()
|
||||||
|
|||||||
Reference in new issue
Block a user