Move block audit cache to apiService
This commit is contained in:
parent
99ea1ad0a0
commit
c3b9828d42
@ -295,7 +295,6 @@ export class BlockComponent implements OnInit, OnDestroy {
|
|||||||
),
|
),
|
||||||
!this.isAuditAvailableFromBlockHeight(block.height) ? of(null) : this.apiService.getBlockAudit$(block.id)
|
!this.isAuditAvailableFromBlockHeight(block.height) ? of(null) : this.apiService.getBlockAudit$(block.id)
|
||||||
.pipe(
|
.pipe(
|
||||||
tap(() => this.cacheService.setBlockAuditLoaded(block.id)),
|
|
||||||
catchError((err) => {
|
catchError((err) => {
|
||||||
this.overviewError = err;
|
this.overviewError = err;
|
||||||
return of(null);
|
return of(null);
|
||||||
|
@ -322,7 +322,6 @@ export class TrackerComponent implements OnInit, OnDestroy {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
fetchAudit ? this.apiService.getBlockAudit$(hash).pipe(
|
fetchAudit ? this.apiService.getBlockAudit$(hash).pipe(
|
||||||
tap((blockAudit) => this.cacheService.setBlockAuditLoaded(hash)),
|
|
||||||
map(audit => {
|
map(audit => {
|
||||||
const isAdded = audit.addedTxs.includes(txid);
|
const isAdded = audit.addedTxs.includes(txid);
|
||||||
const isPrioritized = audit.prioritizedTxs.includes(txid);
|
const isPrioritized = audit.prioritizedTxs.includes(txid);
|
||||||
|
@ -366,7 +366,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
const fetchAudit = auditAvailable && !isCoinbase;
|
const fetchAudit = auditAvailable && !isCoinbase;
|
||||||
if (fetchAudit) {
|
if (fetchAudit) {
|
||||||
// If block audit is already cached, use it to get transaction audit
|
// If block audit is already cached, use it to get transaction audit
|
||||||
const blockAuditLoaded = this.cacheService.getBlockAuditLoaded(hash);
|
const blockAuditLoaded = this.apiService.getBlockAuditLoaded(hash);
|
||||||
if (blockAuditLoaded) {
|
if (blockAuditLoaded) {
|
||||||
return this.apiService.getBlockAudit$(hash).pipe(
|
return this.apiService.getBlockAudit$(hash).pipe(
|
||||||
map(audit => {
|
map(audit => {
|
||||||
|
@ -18,6 +18,7 @@ export class ApiService {
|
|||||||
private apiBasePath: string; // network path is /testnet, etc. or '' for mainnet
|
private apiBasePath: string; // network path is /testnet, etc. or '' for mainnet
|
||||||
|
|
||||||
private requestCache = new Map<string, { subject: BehaviorSubject<any>, expiry: number }>;
|
private requestCache = new Map<string, { subject: BehaviorSubject<any>, expiry: number }>;
|
||||||
|
public blockAuditLoaded: { [hash: string]: boolean } = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private httpClient: HttpClient,
|
private httpClient: HttpClient,
|
||||||
@ -370,6 +371,7 @@ export class ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBlockAudit$(hash: string) : Observable<BlockAudit> {
|
getBlockAudit$(hash: string) : Observable<BlockAudit> {
|
||||||
|
this.setBlockAuditLoaded(hash);
|
||||||
return this.httpClient.get<BlockAudit>(
|
return this.httpClient.get<BlockAudit>(
|
||||||
this.apiBaseUrl + this.apiBasePath + `/api/v1/block/${hash}/audit-summary`
|
this.apiBaseUrl + this.apiBasePath + `/api/v1/block/${hash}/audit-summary`
|
||||||
);
|
);
|
||||||
@ -533,4 +535,13 @@ export class ApiService {
|
|||||||
this.apiBaseUrl + this.apiBasePath + '/api/v1/accelerations/total' + (queryString?.length ? '?' + queryString : '')
|
this.apiBaseUrl + this.apiBasePath + '/api/v1/accelerations/total' + (queryString?.length ? '?' + queryString : '')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache methods
|
||||||
|
async setBlockAuditLoaded(hash: string) {
|
||||||
|
this.blockAuditLoaded[hash] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getBlockAuditLoaded(hash) {
|
||||||
|
return this.blockAuditLoaded[hash];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ export class CacheService {
|
|||||||
network: string;
|
network: string;
|
||||||
blockHashCache: { [hash: string]: BlockExtended } = {};
|
blockHashCache: { [hash: string]: BlockExtended } = {};
|
||||||
blockCache: { [height: number]: BlockExtended } = {};
|
blockCache: { [height: number]: BlockExtended } = {};
|
||||||
blockAuditLoaded: { [hash: string]: boolean } = {};
|
|
||||||
blockLoading: { [height: number]: boolean } = {};
|
blockLoading: { [height: number]: boolean } = {};
|
||||||
copiesInBlockQueue: { [height: number]: number } = {};
|
copiesInBlockQueue: { [height: number]: number } = {};
|
||||||
blockPriorities: number[] = [];
|
blockPriorities: number[] = [];
|
||||||
@ -98,10 +97,6 @@ export class CacheService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setBlockAuditLoaded(hash: string) {
|
|
||||||
this.blockAuditLoaded[hash] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// increase the priority of a block, to delay removal
|
// increase the priority of a block, to delay removal
|
||||||
bumpBlockPriority(height) {
|
bumpBlockPriority(height) {
|
||||||
this.blockPriorities.push(height);
|
this.blockPriorities.push(height);
|
||||||
@ -129,7 +124,7 @@ export class CacheService {
|
|||||||
resetBlockCache() {
|
resetBlockCache() {
|
||||||
this.blockHashCache = {};
|
this.blockHashCache = {};
|
||||||
this.blockCache = {};
|
this.blockCache = {};
|
||||||
this.blockAuditLoaded = {};
|
this.apiService.blockAuditLoaded = {};
|
||||||
this.blockLoading = {};
|
this.blockLoading = {};
|
||||||
this.copiesInBlockQueue = {};
|
this.copiesInBlockQueue = {};
|
||||||
this.blockPriorities = [];
|
this.blockPriorities = [];
|
||||||
@ -138,8 +133,4 @@ export class CacheService {
|
|||||||
getCachedBlock(height) {
|
getCachedBlock(height) {
|
||||||
return this.blockCache[height];
|
return this.blockCache[height];
|
||||||
}
|
}
|
||||||
|
|
||||||
getBlockAuditLoaded(hash) {
|
|
||||||
return this.blockAuditLoaded[hash];
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user