Preload the previous block - Disable 300 ms on block page

This commit is contained in:
nymkappa 2022-06-22 23:17:49 +02:00
parent 2d6fcd6d67
commit da28e7b80e
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04

View File

@ -54,6 +54,9 @@ export class BlockComponent implements OnInit, OnDestroy {
blocksSubscription: Subscription; blocksSubscription: Subscription;
networkChangedSubscription: Subscription; networkChangedSubscription: Subscription;
queryParamsSubscription: Subscription; queryParamsSubscription: Subscription;
nextBlockSubscription: Subscription = undefined;
nextBlockSummarySubscription: Subscription = undefined;
nextBlockTxListSubscription: Subscription = undefined;
@ViewChild('blockGraph') blockGraph: BlockOverviewGraphComponent; @ViewChild('blockGraph') blockGraph: BlockOverviewGraphComponent;
@ -152,6 +155,14 @@ export class BlockComponent implements OnInit, OnDestroy {
} }
}), }),
tap((block: BlockExtended) => { tap((block: BlockExtended) => {
// Preload previous block summary (execute the http query so the response will be cached)
this.unsubscribeNextBlockSubscriptions();
setTimeout(() => {
this.nextBlockSubscription = this.apiService.getBlock$(block.previousblockhash).subscribe();
this.nextBlockTxListSubscription = this.electrsApiService.getBlockTransactions$(block.previousblockhash).subscribe();
this.nextBlockSummarySubscription = this.apiService.getStrippedBlockTransactions$(block.previousblockhash).subscribe();
}, 100);
this.block = block; this.block = block;
this.blockHeight = block.height; this.blockHeight = block.height;
const direction = (this.lastBlockHeight < this.blockHeight) ? 'right' : 'left'; const direction = (this.lastBlockHeight < this.blockHeight) ? 'right' : 'left';
@ -176,7 +187,6 @@ export class BlockComponent implements OnInit, OnDestroy {
this.blockGraph.exit(direction); this.blockGraph.exit(direction);
} }
}), }),
debounceTime(300),
shareReplay(1) shareReplay(1)
); );
this.transactionSubscription = block$.pipe( this.transactionSubscription = block$.pipe(
@ -273,6 +283,19 @@ export class BlockComponent implements OnInit, OnDestroy {
this.blocksSubscription.unsubscribe(); this.blocksSubscription.unsubscribe();
this.networkChangedSubscription.unsubscribe(); this.networkChangedSubscription.unsubscribe();
this.queryParamsSubscription.unsubscribe(); this.queryParamsSubscription.unsubscribe();
this.unsubscribeNextBlockSubscriptions();
}
unsubscribeNextBlockSubscriptions() {
if (this.nextBlockSubscription !== undefined) {
this.nextBlockSubscription.unsubscribe();
}
if (this.nextBlockSummarySubscription !== undefined) {
this.nextBlockSummarySubscription.unsubscribe();
}
if (this.nextBlockTxListSubscription !== undefined) {
this.nextBlockTxListSubscription.unsubscribe();
}
} }
// TODO - Refactor this.fees/this.reward for liquid because it is not // TODO - Refactor this.fees/this.reward for liquid because it is not