problem: doesn't cache transactions requested for a block
This commit is contained in:
@@ -97,9 +97,10 @@ open class Caches(
|
||||
return
|
||||
}
|
||||
memTxsByHash.add(tx)
|
||||
memBlocksByHash.get(tx.blockId)?.let { block ->
|
||||
redisTxsByHash?.add(tx, block)
|
||||
}
|
||||
//TODO move subscription to the caller
|
||||
getBlocksByHash().read(tx.blockId).flatMap { block ->
|
||||
redisTxsByHash?.add(tx, block) ?: Mono.empty()
|
||||
}.subscribe()
|
||||
}
|
||||
|
||||
fun cache(tag: Tag, block: BlockContainer) {
|
||||
@@ -142,11 +143,11 @@ open class Caches(
|
||||
val transactions = plainTransactions.map { tx ->
|
||||
TxContainer.from(tx)
|
||||
}
|
||||
transactions.forEach {
|
||||
cache(Tag.REQUESTED, it)
|
||||
}
|
||||
if (redisTxsByHash != null) {
|
||||
job.add(Flux.fromIterable(transactions).flatMap { redisTxsByHash.add(it, block) }.then())
|
||||
job.add(Flux.fromIterable(transactions)
|
||||
.doOnNext { memTxsByHash.add(it) }
|
||||
.flatMap { redisTxsByHash.add(it, block) }
|
||||
.then())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ abstract class OnTxRedisCache<T>(
|
||||
}
|
||||
}
|
||||
|
||||
fun add(id: TxId, value: T, block: BlockContainer?, blockHeight: Long?): Mono<Void> {
|
||||
open fun add(id: TxId, value: T, block: BlockContainer?, blockHeight: Long?): Mono<Void> {
|
||||
return Mono.just(id)
|
||||
.flatMap {
|
||||
val key = key(it)
|
||||
|
||||
@@ -35,7 +35,7 @@ import kotlin.math.min
|
||||
/**
|
||||
* Cache transactions in Redis, up to 24 hours.
|
||||
*/
|
||||
class TxRedisCache(
|
||||
open class TxRedisCache(
|
||||
private val redis: RedisReactiveCommands<String, ByteArray>,
|
||||
private val chain: Chain
|
||||
) : Reader<TxId, TxContainer>,
|
||||
@@ -74,7 +74,7 @@ class TxRedisCache(
|
||||
)
|
||||
}
|
||||
|
||||
fun add(tx: TxContainer, block: BlockContainer): Mono<Void> {
|
||||
open fun add(tx: TxContainer, block: BlockContainer): Mono<Void> {
|
||||
return super.add(tx.hash, tx, block, tx.height)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user