mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 02:37:22 +01:00
Adds a flatten to set utility
This commit is contained in:
@@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.equalImmutabl
|
|||||||
import com.vitorpamplona.ammolite.relays.BundledInsert
|
import com.vitorpamplona.ammolite.relays.BundledInsert
|
||||||
import com.vitorpamplona.ammolite.relays.BundledUpdate
|
import com.vitorpamplona.ammolite.relays.BundledUpdate
|
||||||
import com.vitorpamplona.quartz.utils.Log
|
import com.vitorpamplona.quartz.utils.Log
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -160,7 +161,7 @@ class ChannelFeedContentState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun invalidateInsertData(newItems: Set<Note>) {
|
fun invalidateInsertData(newItems: Set<Note>) {
|
||||||
bundlerInsert.invalidateList(newItems) { refreshFromOldState(it.flatten().toSet()) }
|
bundlerInsert.invalidateList(newItems) { refreshFromOldState(it.flattenToSet()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateFeedWith(newNotes: Set<Note>) {
|
fun updateFeedWith(newNotes: Set<Note>) {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.equalImmutabl
|
|||||||
import com.vitorpamplona.ammolite.relays.BasicBundledInsert
|
import com.vitorpamplona.ammolite.relays.BasicBundledInsert
|
||||||
import com.vitorpamplona.ammolite.relays.BasicBundledUpdate
|
import com.vitorpamplona.ammolite.relays.BasicBundledUpdate
|
||||||
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
|
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -212,7 +213,7 @@ class FeedContentState(
|
|||||||
|
|
||||||
fun invalidateInsertData(newItems: Set<Note>) {
|
fun invalidateInsertData(newItems: Set<Note>) {
|
||||||
bundlerInsert.invalidateList(newItems) {
|
bundlerInsert.invalidateList(newItems) {
|
||||||
refreshFromOldState(it.flatten().toSet())
|
refreshFromOldState(it.flattenToSet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import com.vitorpamplona.quartz.nip28PublicChat.admin.ChannelMetadataEvent
|
|||||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent
|
import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent
|
||||||
import com.vitorpamplona.quartz.nip58Badges.BadgeAwardEvent
|
import com.vitorpamplona.quartz.nip58Badges.BadgeAwardEvent
|
||||||
import com.vitorpamplona.quartz.utils.Log
|
import com.vitorpamplona.quartz.utils.Log
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -426,7 +427,7 @@ class CardFeedContentState(
|
|||||||
|
|
||||||
fun invalidateInsertData(newItems: Set<Note>) {
|
fun invalidateInsertData(newItems: Set<Note>) {
|
||||||
bundlerInsert.invalidateList(newItems) {
|
bundlerInsert.invalidateList(newItems) {
|
||||||
val newObjects = it.flatten().toSet()
|
val newObjects = it.flattenToSet()
|
||||||
logTime("${this.javaClass.simpleName} Card additive receiving ${newObjects.size} items into ${it.size} items") {
|
logTime("${this.javaClass.simpleName} Card additive receiving ${newObjects.size} items into ${it.size} items") {
|
||||||
if (newObjects.isNotEmpty()) {
|
if (newObjects.isNotEmpty()) {
|
||||||
refreshFromOldState(newObjects)
|
refreshFromOldState(newObjects)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.vitorpamplona.amethyst.model.User
|
|||||||
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder
|
import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder
|
||||||
import com.vitorpamplona.quartz.nip89AppHandlers.recommendation.AppRecommendationEvent
|
import com.vitorpamplona.quartz.nip89AppHandlers.recommendation.AppRecommendationEvent
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
|
|
||||||
class UserProfileAppRecommendationsFeedFilter(
|
class UserProfileAppRecommendationsFeedFilter(
|
||||||
val user: User,
|
val user: User,
|
||||||
@@ -43,7 +44,7 @@ class UserProfileAppRecommendationsFeedFilter(
|
|||||||
|
|
||||||
override fun applyFilter(newItems: Set<Note>): Set<Note> = innerApplyFilter(newItems)
|
override fun applyFilter(newItems: Set<Note>): Set<Note> = innerApplyFilter(newItems)
|
||||||
|
|
||||||
private fun innerApplyFilter(collection: Collection<Note>): Set<Note> = collection.mapNotNull { filterMap(it) }.flatten().toSet()
|
private fun innerApplyFilter(collection: Collection<Note>): Set<Note> = collection.mapNotNull { filterMap(it) }.flattenToSet()
|
||||||
|
|
||||||
fun filterMap(it: Note): List<Note>? {
|
fun filterMap(it: Note): List<Note>? {
|
||||||
val noteEvent = it.event
|
val noteEvent = it.event
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventStore
|
|||||||
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
|
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
|
||||||
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
||||||
import com.vitorpamplona.quartz.utils.Log
|
import com.vitorpamplona.quartz.utils.Log
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
@@ -72,8 +73,8 @@ class LargeDBInsertBenchmark : BaseLargeCacheBenchmark() {
|
|||||||
fun bench40DeletionRequestsEvents() {
|
fun bench40DeletionRequestsEvents() {
|
||||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
val deletions = allEvents.filterIsInstance<DeletionEvent>()
|
val deletions = allEvents.filterIsInstance<DeletionEvent>()
|
||||||
val deletionIds = deletions.map { it.deleteEventIds() }.flatten().toSet()
|
val deletionIds = deletions.map { it.deleteEventIds() }.flattenToSet()
|
||||||
val deletionAddresses = deletions.map { it.deleteAddressIds() }.flatten().toSet()
|
val deletionAddresses = deletions.map { it.deleteAddressIds() }.flattenToSet()
|
||||||
|
|
||||||
val toBeDeletedEvents =
|
val toBeDeletedEvents =
|
||||||
allEvents.filter {
|
allEvents.filter {
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip01Core.tags.hashtags
|
package com.vitorpamplona.quartz.nip01Core.tags.hashtags
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.utils.flattenToSet
|
||||||
|
|
||||||
fun hashtagAlts(tag: String): Set<String> =
|
fun hashtagAlts(tag: String): Set<String> =
|
||||||
setOf(
|
setOf(
|
||||||
tag,
|
tag,
|
||||||
@@ -30,6 +32,6 @@ fun hashtagAlts(tag: String): Set<String> =
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
fun hashtagAlts(tags: List<String>): Set<String> = tags.map { hashtagAlts(it) }.flatten().toSet()
|
fun hashtagAlts(tags: List<String>): Set<String> = tags.map { hashtagAlts(it) }.flattenToSet()
|
||||||
|
|
||||||
fun hashtagAlts(tags: Set<String>): Set<String> = tags.map { hashtagAlts(it) }.flatten().toSet()
|
fun hashtagAlts(tags: Set<String>): Set<String> = tags.map { hashtagAlts(it) }.flattenToSet()
|
||||||
|
|||||||
@@ -46,3 +46,11 @@ fun <T> Iterable<T>.joinToStringLimited(
|
|||||||
buffer.append(postfix)
|
buffer.append(postfix)
|
||||||
return buffer.toString()
|
return buffer.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun <T> Iterable<Iterable<T>>.flattenToSet(): Set<T> {
|
||||||
|
val result = mutableSetOf<T>()
|
||||||
|
for (element in this) {
|
||||||
|
result.addAll(element)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user