Changes the follower calculation to only store when important to the user.
This commit is contained in:
@@ -16,14 +16,13 @@ import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
|
|||||||
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
|
import fr.acinq.secp256k1.Hex
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.Collections
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
|
||||||
import fr.acinq.secp256k1.Hex
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
import kotlin.time.measureTimedValue
|
import kotlin.time.measureTimedValue
|
||||||
@@ -42,7 +41,6 @@ import nostr.postr.events.PrivateDmEvent
|
|||||||
import nostr.postr.events.RecommendRelayEvent
|
import nostr.postr.events.RecommendRelayEvent
|
||||||
import nostr.postr.events.TextNoteEvent
|
import nostr.postr.events.TextNoteEvent
|
||||||
import nostr.postr.toHex
|
import nostr.postr.toHex
|
||||||
import nostr.postr.toNpub
|
|
||||||
|
|
||||||
|
|
||||||
object LocalCache {
|
object LocalCache {
|
||||||
@@ -198,29 +196,27 @@ object LocalCache {
|
|||||||
//Log.d("RR", event.toJson())
|
//Log.d("RR", event.toJson())
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
fun consume(event: ContactListEvent) {
|
fun consume(event: ContactListEvent) {
|
||||||
val user = getOrCreateUser(event.pubKey.toHexKey())
|
val user = getOrCreateUser(event.pubKey.toHexKey())
|
||||||
|
|
||||||
if (event.createdAt > user.updatedFollowsAt) {
|
if (event.createdAt > user.updatedFollowsAt) {
|
||||||
val (value, elapsed) = measureTimedValue {
|
user.updateFollows(
|
||||||
user.updateFollows(
|
event.follows.map {
|
||||||
event.follows.map {
|
try {
|
||||||
try {
|
val pubKey = decodePublicKey(it.pubKeyHex)
|
||||||
val pubKey = decodePublicKey(it.pubKeyHex)
|
getOrCreateUser(pubKey.toHexKey())
|
||||||
getOrCreateUser(pubKey.toHexKey())
|
} catch (e: Exception) {
|
||||||
} catch (e: Exception) {
|
println("Could not parse Hex key: ${it.pubKeyHex}")
|
||||||
println("Could not parse Hex key: ${it.pubKeyHex}")
|
println("UpdateFollows: " + event.toJson())
|
||||||
println("UpdateFollows: " + event.toJson())
|
e.printStackTrace()
|
||||||
e.printStackTrace()
|
null
|
||||||
null
|
}
|
||||||
}
|
}.filterNotNull().toSet(),
|
||||||
}.filterNotNull().toSet(),
|
event.createdAt
|
||||||
event.createdAt
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val (valueRelays, elapsedRelays) = measureTimedValue {
|
// Saves relay list only if it's a user that is currently been seen
|
||||||
|
if (user.liveSet?.isInUse() == true) {
|
||||||
try {
|
try {
|
||||||
if (event.content.isNotEmpty()) {
|
if (event.content.isNotEmpty()) {
|
||||||
val relays: Map<String, ContactListEvent.ReadWrite> =
|
val relays: Map<String, ContactListEvent.ReadWrite> =
|
||||||
@@ -234,11 +230,15 @@ object LocalCache {
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves relay list only if it's a user that is currently been seen
|
||||||
|
user.latestContactList = event
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("CL", "AAA ${user.toBestDisplayName()} ${event.follows.size} in ${elapsed} and \t${elapsedRelays}")
|
Log.d(
|
||||||
|
"CL",
|
||||||
user.latestContactList = event
|
"AAA ${user.toBestDisplayName()} ${event.follows.size}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class User(val pubkeyHex: String) {
|
|||||||
fun follow(users: Set<User>, followedAt: Long) {
|
fun follow(users: Set<User>, followedAt: Long) {
|
||||||
follows = follows + users
|
follows = follows + users
|
||||||
users.forEach {
|
users.forEach {
|
||||||
if (this !in it.followers) {
|
if (this !in it.followers && it.liveSet?.isInUse() == true) {
|
||||||
it.followers = it.followers + this
|
it.followers = it.followers + this
|
||||||
it.liveSet?.follows?.invalidateData()
|
it.liveSet?.follows?.invalidateData()
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ class User(val pubkeyHex: String) {
|
|||||||
fun unfollow(users: Set<User>) {
|
fun unfollow(users: Set<User>) {
|
||||||
follows = follows - users
|
follows = follows - users
|
||||||
users.forEach {
|
users.forEach {
|
||||||
if (this in it.followers) {
|
if (this in it.followers && it.liveSet?.isInUse() == true) {
|
||||||
it.followers = it.followers - this
|
it.followers = it.followers - this
|
||||||
it.liveSet?.follows?.invalidateData()
|
it.liveSet?.follows?.invalidateData()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user