mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 15:46:48 +01:00
Offers an interface to BaseEoseManager objects
This commit is contained in:
@@ -29,17 +29,25 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
|||||||
import com.vitorpamplona.quartz.utils.Log
|
import com.vitorpamplona.quartz.utils.Log
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
interface IEoseManager {
|
||||||
|
fun invalidateFilters(ignoreIfDoing: Boolean = false)
|
||||||
|
|
||||||
|
fun destroy()
|
||||||
|
|
||||||
|
fun printStats()
|
||||||
|
}
|
||||||
|
|
||||||
abstract class BaseEoseManager<T>(
|
abstract class BaseEoseManager<T>(
|
||||||
val client: INostrClient,
|
val client: INostrClient,
|
||||||
val allKeys: () -> Set<T>,
|
val allKeys: () -> Set<T>,
|
||||||
) {
|
) : IEoseManager {
|
||||||
protected val logTag: String = this.javaClass.simpleName
|
protected val logTag: String = this.javaClass.simpleName
|
||||||
|
|
||||||
private val orchestrator = SubscriptionController(client)
|
private val orchestrator = SubscriptionController(client)
|
||||||
|
|
||||||
abstract fun updateSubscriptions(keys: Set<T>)
|
abstract fun updateSubscriptions(keys: Set<T>)
|
||||||
|
|
||||||
fun printStats() = orchestrator.printStats(logTag)
|
override fun printStats() = orchestrator.printStats(logTag)
|
||||||
|
|
||||||
fun newSubscriptionId() = if (isDebug) logTag + newSubId() else newSubId()
|
fun newSubscriptionId() = if (isDebug) logTag + newSubId() else newSubId()
|
||||||
|
|
||||||
@@ -52,19 +60,16 @@ abstract class BaseEoseManager<T>(
|
|||||||
// Refreshes observers in batches.
|
// Refreshes observers in batches.
|
||||||
private val bundler = BundledUpdate(500, Dispatchers.Default)
|
private val bundler = BundledUpdate(500, Dispatchers.Default)
|
||||||
|
|
||||||
fun invalidateFilters() {
|
override fun invalidateFilters(ignoreIfDoing: Boolean) {
|
||||||
bundler.invalidate {
|
bundler.invalidate(ignoreIfDoing, ::forceInvalidate)
|
||||||
forceInvalidate()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun forceInvalidate() {
|
fun forceInvalidate() {
|
||||||
updateSubscriptions(allKeys())
|
updateSubscriptions(allKeys())
|
||||||
|
|
||||||
orchestrator.updateRelays()
|
orchestrator.updateRelays()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroy() {
|
override fun destroy() {
|
||||||
bundler.cancel()
|
bundler.cancel()
|
||||||
orchestrator.destroy()
|
orchestrator.destroy()
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
|
|||||||
Reference in New Issue
Block a user