Merge pull request #5038 from mempool/mononaut/improve-deferred-mempool-animations

Improve deferred mempool visualization updates
This commit is contained in:
softsimon 2024-05-06 22:40:12 +07:00 committed by GitHub
commit 375e43c191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -238,7 +238,7 @@ export class BlockOverviewGraphComponent implements AfterViewInit, OnDestroy, On
} }
} }
// collates non-urgent updates into a set of consistent pending changes // collates deferred updates into a set of consistent pending changes
queueUpdate(add: TransactionStripped[], remove: string[], change: { txid: string, rate: number | undefined, acc: boolean | undefined }[], direction: string = 'left'): void { queueUpdate(add: TransactionStripped[], remove: string[], change: { txid: string, rate: number | undefined, acc: boolean | undefined }[], direction: string = 'left'): void {
for (const tx of add) { for (const tx of add) {
this.pendingUpdate.add[tx.txid] = tx; this.pendingUpdate.add[tx.txid] = tx;
@ -262,9 +262,15 @@ export class BlockOverviewGraphComponent implements AfterViewInit, OnDestroy, On
this.pendingUpdate.count++; this.pendingUpdate.count++;
} }
deferredUpdate(add: TransactionStripped[], remove: string[], change: { txid: string, rate: number | undefined, acc: boolean | undefined }[], direction: string = 'left'): void {
this.queueUpdate(add, remove, change, direction);
this.applyQueuedUpdates();
}
applyQueuedUpdates(): void { applyQueuedUpdates(): void {
if (this.pendingUpdate.count && performance.now() > (this.lastUpdate + this.animationDuration)) { if (this.pendingUpdate.count && performance.now() > (this.lastUpdate + this.animationDuration)) {
this.update([], [], [], this.pendingUpdate?.direction); this.applyUpdate(Object.values(this.pendingUpdate.add), Object.values(this.pendingUpdate.remove), Object.values(this.pendingUpdate.change), this.pendingUpdate.direction);
this.clearUpdateQueue();
} }
} }

View file

@ -144,7 +144,7 @@ export class MempoolBlockOverviewComponent implements OnInit, OnDestroy, OnChang
if (blockMined) { if (blockMined) {
this.blockGraph.update(delta.added, delta.removed, delta.changed || [], blockMined ? this.chainDirection : this.poolDirection, blockMined); this.blockGraph.update(delta.added, delta.removed, delta.changed || [], blockMined ? this.chainDirection : this.poolDirection, blockMined);
} else { } else {
this.blockGraph.queueUpdate(delta.added, delta.removed, delta.changed || [], this.poolDirection); this.blockGraph.deferredUpdate(delta.added, delta.removed, delta.changed || [], this.poolDirection);
} }
} }