Gets rid of the update bundler for Notes, Users and Channel.
This commit is contained in:
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.model
|
|||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder
|
import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|
||||||
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache
|
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
|
import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
@@ -42,7 +41,6 @@ import com.vitorpamplona.quartz.nip28PublicChat.base.ChannelData
|
|||||||
import com.vitorpamplona.quartz.nip53LiveActivities.streaming.LiveActivitiesEvent
|
import com.vitorpamplona.quartz.nip53LiveActivities.streaming.LiveActivitiesEvent
|
||||||
import com.vitorpamplona.quartz.utils.Hex
|
import com.vitorpamplona.quartz.utils.Hex
|
||||||
import com.vitorpamplona.quartz.utils.LargeCache
|
import com.vitorpamplona.quartz.utils.LargeCache
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -291,7 +289,6 @@ abstract class Channel(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flowSet != null && flowSet?.isInUse() == false) {
|
if (flowSet != null && flowSet?.isInUse() == false) {
|
||||||
flowSet?.destroy()
|
|
||||||
flowSet = null
|
flowSet = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,28 +319,15 @@ class ChannelFlowSet(
|
|||||||
fun isInUse(): Boolean =
|
fun isInUse(): Boolean =
|
||||||
metadata.hasObservers() ||
|
metadata.hasObservers() ||
|
||||||
notes.hasObservers()
|
notes.hasObservers()
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
metadata.destroy()
|
|
||||||
notes.destroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChannelFlow(
|
class ChannelFlow(
|
||||||
val channel: Channel,
|
val channel: Channel,
|
||||||
) {
|
) {
|
||||||
// Refreshes observers in batches.
|
|
||||||
private val bundler = BundledUpdate(300, Dispatchers.IO)
|
|
||||||
val stateFlow = MutableStateFlow(ChannelState(channel))
|
val stateFlow = MutableStateFlow(ChannelState(channel))
|
||||||
|
|
||||||
fun invalidateData() {
|
fun invalidateData() {
|
||||||
bundler.invalidate {
|
stateFlow.tryEmit(ChannelState(channel))
|
||||||
stateFlow.emit(ChannelState(channel))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
bundler.cancel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
||||||
|
|||||||
@@ -2355,12 +2355,6 @@ object LocalCache : ILocalCache {
|
|||||||
|
|
||||||
removeFromCache(childrenToBeRemoved)
|
removeFromCache(childrenToBeRemoved)
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
|
||||||
it.replyTo?.forEach { masterNote ->
|
|
||||||
masterNote.clearEOSE() // allows reloading of these events
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toBeRemoved.size > 1) {
|
if (toBeRemoved.size > 1) {
|
||||||
println("PRUNE: ${toBeRemoved.size} thread replies removed.")
|
println("PRUNE: ${toBeRemoved.size} thread replies removed.")
|
||||||
}
|
}
|
||||||
@@ -2373,7 +2367,6 @@ object LocalCache : ILocalCache {
|
|||||||
masterNote.removeReaction(note)
|
masterNote.removeReaction(note)
|
||||||
masterNote.removeZap(note)
|
masterNote.removeZap(note)
|
||||||
masterNote.removeReport(note)
|
masterNote.removeReport(note)
|
||||||
masterNote.clearEOSE() // allows reloading of these events if needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val noteEvent = note.event
|
val noteEvent = note.event
|
||||||
|
|||||||
@@ -25,11 +25,9 @@ import androidx.compose.runtime.Stable
|
|||||||
import com.vitorpamplona.amethyst.launchAndWaitAll
|
import com.vitorpamplona.amethyst.launchAndWaitAll
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.amethyst.service.firstFullCharOrEmoji
|
import com.vitorpamplona.amethyst.service.firstFullCharOrEmoji
|
||||||
import com.vitorpamplona.amethyst.service.relays.EOSERelayList
|
|
||||||
import com.vitorpamplona.amethyst.service.replace
|
import com.vitorpamplona.amethyst.service.replace
|
||||||
import com.vitorpamplona.amethyst.tryAndWait
|
import com.vitorpamplona.amethyst.tryAndWait
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|
||||||
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache
|
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.quartz.experimental.bounties.addedRewardValue
|
import com.vitorpamplona.quartz.experimental.bounties.addedRewardValue
|
||||||
import com.vitorpamplona.quartz.experimental.bounties.hasAdditionalReward
|
import com.vitorpamplona.quartz.experimental.bounties.hasAdditionalReward
|
||||||
@@ -76,7 +74,6 @@ import com.vitorpamplona.quartz.utils.Hex
|
|||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import com.vitorpamplona.quartz.utils.containsAny
|
import com.vitorpamplona.quartz.utils.containsAny
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
@@ -162,8 +159,6 @@ open class Note(
|
|||||||
var relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
var relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var lastReactionsDownloadTime: EOSERelayList = EOSERelayList()
|
|
||||||
|
|
||||||
fun id() = Hex.decode(idHex)
|
fun id() = Hex.decode(idHex)
|
||||||
|
|
||||||
open fun idNote() = toNEvent()
|
open fun idNote() = toNEvent()
|
||||||
@@ -298,7 +293,6 @@ open class Note(
|
|||||||
zapPayments = mapOf<Note, Note?>()
|
zapPayments = mapOf<Note, Note?>()
|
||||||
zapsAmount = BigDecimal.ZERO
|
zapsAmount = BigDecimal.ZERO
|
||||||
relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
||||||
lastReactionsDownloadTime.clear()
|
|
||||||
|
|
||||||
if (repliesChanged) flowSet?.replies?.invalidateData()
|
if (repliesChanged) flowSet?.replies?.invalidateData()
|
||||||
if (reactionsChanged) flowSet?.reactions?.invalidateData()
|
if (reactionsChanged) flowSet?.reactions?.invalidateData()
|
||||||
@@ -386,11 +380,10 @@ open class Note(
|
|||||||
zapRequest: Note,
|
zapRequest: Note,
|
||||||
zap: Note?,
|
zap: Note?,
|
||||||
) {
|
) {
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
if (zaps[zapRequest] == null) {
|
if (zaps[zapRequest] == null) {
|
||||||
val inserted = innerAddZap(zapRequest, zap)
|
val inserted = innerAddZap(zapRequest, zap)
|
||||||
if (inserted) {
|
println("AABBCC addZap $inserted")
|
||||||
|
if (inserted && zap != null) {
|
||||||
updateZapTotal()
|
updateZapTotal()
|
||||||
flowSet?.zaps?.invalidateData()
|
flowSet?.zaps?.invalidateData()
|
||||||
}
|
}
|
||||||
@@ -830,10 +823,6 @@ open class Note(
|
|||||||
zapsAmount = BigDecimal.ZERO
|
zapsAmount = BigDecimal.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearEOSE() {
|
|
||||||
lastReactionsDownloadTime.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isHiddenFor(accountChoices: Account.LiveHiddenUsers): Boolean {
|
fun isHiddenFor(accountChoices: Account.LiveHiddenUsers): Boolean {
|
||||||
val thisEvent = event ?: return false
|
val thisEvent = event ?: return false
|
||||||
val hash = thisEvent.pubKey.hashCode()
|
val hash = thisEvent.pubKey.hashCode()
|
||||||
@@ -886,7 +875,6 @@ open class Note(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flowSet != null && flowSet?.isInUse() == false) {
|
if (flowSet != null && flowSet?.isInUse() == false) {
|
||||||
flowSet?.destroy()
|
|
||||||
flowSet = null
|
flowSet = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -986,18 +974,6 @@ class NoteFlowSet(
|
|||||||
zaps.hasObservers() ||
|
zaps.hasObservers() ||
|
||||||
ots.hasObservers() ||
|
ots.hasObservers() ||
|
||||||
edits.hasObservers()
|
edits.hasObservers()
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
metadata.destroy()
|
|
||||||
reports.destroy()
|
|
||||||
relays.destroy()
|
|
||||||
reactions.destroy()
|
|
||||||
boosts.destroy()
|
|
||||||
replies.destroy()
|
|
||||||
zaps.destroy()
|
|
||||||
ots.destroy()
|
|
||||||
edits.destroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -1005,18 +981,10 @@ class NoteBundledRefresherFlow(
|
|||||||
val note: Note,
|
val note: Note,
|
||||||
) {
|
) {
|
||||||
// Refreshes observers in batches.
|
// Refreshes observers in batches.
|
||||||
// TODO: Replace the bundler for .sample
|
|
||||||
private val bundler = BundledUpdate(500, Dispatchers.IO)
|
|
||||||
val stateFlow = MutableStateFlow(NoteState(note))
|
val stateFlow = MutableStateFlow(NoteState(note))
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
bundler.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun invalidateData() {
|
fun invalidateData() {
|
||||||
bundler.invalidate {
|
stateFlow.tryEmit(NoteState(note))
|
||||||
stateFlow.emit(NoteState(note))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import androidx.compose.runtime.Immutable
|
|||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|
||||||
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache.RelayBriefInfo
|
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache.RelayBriefInfo
|
||||||
import com.vitorpamplona.quartz.lightning.Lud06
|
import com.vitorpamplona.quartz.lightning.Lud06
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
@@ -48,7 +47,6 @@ import com.vitorpamplona.quartz.utils.DualCase
|
|||||||
import com.vitorpamplona.quartz.utils.Hex
|
import com.vitorpamplona.quartz.utils.Hex
|
||||||
import com.vitorpamplona.quartz.utils.containsAny
|
import com.vitorpamplona.quartz.utils.containsAny
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@@ -397,7 +395,6 @@ class User(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flowSet != null && flowSet?.isInUse() == false) {
|
if (flowSet != null && flowSet?.isInUse() == false) {
|
||||||
flowSet?.destroy()
|
|
||||||
flowSet = null
|
flowSet = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,19 +441,6 @@ class UserFlowSet(
|
|||||||
zaps.hasObservers() ||
|
zaps.hasObservers() ||
|
||||||
bookmarks.hasObservers() ||
|
bookmarks.hasObservers() ||
|
||||||
statuses.hasObservers()
|
statuses.hasObservers()
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
metadata.destroy()
|
|
||||||
relays.destroy()
|
|
||||||
follows.destroy()
|
|
||||||
followers.destroy()
|
|
||||||
reports.destroy()
|
|
||||||
messages.destroy()
|
|
||||||
relayInfo.destroy()
|
|
||||||
zaps.destroy()
|
|
||||||
bookmarks.destroy()
|
|
||||||
statuses.destroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -470,22 +454,10 @@ data class RelayInfo(
|
|||||||
class UserBundledRefresherFlow(
|
class UserBundledRefresherFlow(
|
||||||
val user: User,
|
val user: User,
|
||||||
) {
|
) {
|
||||||
// Refreshes observers in batches.
|
|
||||||
private val bundler = BundledUpdate(500, Dispatchers.IO)
|
|
||||||
val stateFlow = MutableStateFlow(UserState(user))
|
val stateFlow = MutableStateFlow(UserState(user))
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
bundler.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun invalidateData() {
|
fun invalidateData() {
|
||||||
checkNotInMainThread()
|
stateFlow.tryEmit(UserState(user))
|
||||||
|
|
||||||
bundler.invalidate {
|
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
stateFlow.emit(UserState(user))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
fun hasObservers() = stateFlow.subscriptionCount.value > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user