Move block audit cache to apiService

This commit is contained in:
natsoni
2024-07-12 16:00:51 +09:00
parent 99ea1ad0a0
commit c3b9828d42
5 changed files with 13 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ export class ApiService {
private apiBasePath: string; // network path is /testnet, etc. or '' for mainnet
private requestCache = new Map<string, { subject: BehaviorSubject<any>, expiry: number }>;
public blockAuditLoaded: { [hash: string]: boolean } = {};
constructor(
private httpClient: HttpClient,
@@ -370,6 +371,7 @@ export class ApiService {
}
getBlockAudit$(hash: string) : Observable<BlockAudit> {
this.setBlockAuditLoaded(hash);
return this.httpClient.get<BlockAudit>(
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 : '')
);
}
// Cache methods
async setBlockAuditLoaded(hash: string) {
this.blockAuditLoaded[hash] = true;
}
getBlockAuditLoaded(hash) {
return this.blockAuditLoaded[hash];
}
}

View File

@@ -20,7 +20,6 @@ export class CacheService {
network: string;
blockHashCache: { [hash: string]: BlockExtended } = {};
blockCache: { [height: number]: BlockExtended } = {};
blockAuditLoaded: { [hash: string]: boolean } = {};
blockLoading: { [height: number]: boolean } = {};
copiesInBlockQueue: { [height: number]: 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
bumpBlockPriority(height) {
this.blockPriorities.push(height);
@@ -129,7 +124,7 @@ export class CacheService {
resetBlockCache() {
this.blockHashCache = {};
this.blockCache = {};
this.blockAuditLoaded = {};
this.apiService.blockAuditLoaded = {};
this.blockLoading = {};
this.copiesInBlockQueue = {};
this.blockPriorities = [];
@@ -138,8 +133,4 @@ export class CacheService {
getCachedBlock(height) {
return this.blockCache[height];
}
getBlockAuditLoaded(hash) {
return this.blockAuditLoaded[hash];
}
}