mirror of
https://github.com/mempool/mempool.git
synced 2025-02-24 14:50:52 +01:00
Merge pull request #5485 from mempool/mononaut/paginated-accel-history
Handle paginated acceleration results
This commit is contained in:
commit
c4b90c2a18
5 changed files with 28 additions and 5 deletions
|
@ -137,7 +137,7 @@ export class BlockPreviewComponent implements OnInit, OnDestroy {
|
|||
})
|
||||
),
|
||||
this.stateService.env.ACCELERATOR === true && block.height > 819500
|
||||
? this.servicesApiService.getAccelerationHistory$({ blockHeight: block.height })
|
||||
? this.servicesApiService.getAllAccelerationHistory$({ blockHeight: block.height })
|
||||
.pipe(catchError(() => {
|
||||
return of([]);
|
||||
}))
|
||||
|
|
|
@ -319,7 +319,7 @@ export class BlockComponent implements OnInit, OnDestroy {
|
|||
this.accelerationsSubscription = this.block$.pipe(
|
||||
switchMap((block) => {
|
||||
return this.stateService.env.ACCELERATOR === true && block.height > 819500
|
||||
? this.servicesApiService.getAccelerationHistory$({ blockHeight: block.height })
|
||||
? this.servicesApiService.getAllAccelerationHistory$({ blockHeight: block.height })
|
||||
.pipe(catchError(() => {
|
||||
return of([]);
|
||||
}))
|
||||
|
|
|
@ -286,7 +286,7 @@ export class TrackerComponent implements OnInit, OnDestroy {
|
|||
this.accelerationInfo = null;
|
||||
}),
|
||||
switchMap((blockHash: string) => {
|
||||
return this.servicesApiService.getAccelerationHistory$({ blockHash });
|
||||
return this.servicesApiService.getAllAccelerationHistory$({ blockHash }, null, this.txId);
|
||||
}),
|
||||
catchError(() => {
|
||||
return of(null);
|
||||
|
|
|
@ -343,7 +343,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||
this.setIsAccelerated();
|
||||
}),
|
||||
switchMap((blockHeight: number) => {
|
||||
return this.servicesApiService.getAccelerationHistory$({ blockHeight }).pipe(
|
||||
return this.servicesApiService.getAllAccelerationHistory$({ blockHeight }, null, this.txId).pipe(
|
||||
switchMap((accelerationHistory: Acceleration[]) => {
|
||||
if (this.tx.acceleration && !accelerationHistory.length) { // If the just mined transaction was accelerated, but services backend did not return any acceleration data, retry
|
||||
return throwError('retry');
|
||||
|
|
|
@ -4,7 +4,7 @@ import { HttpClient } from '@angular/common/http';
|
|||
import { StateService } from './state.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { MenuGroup } from '../interfaces/services.interface';
|
||||
import { Observable, of, ReplaySubject, tap, catchError, share, filter, switchMap } from 'rxjs';
|
||||
import { Observable, of, ReplaySubject, tap, catchError, share, filter, switchMap, map } from 'rxjs';
|
||||
import { IBackendInfo } from '../interfaces/websocket.interface';
|
||||
import { Acceleration, AccelerationHistoryParams } from '../interfaces/node-api.interface';
|
||||
import { AccelerationStats } from '../components/acceleration/acceleration-stats/acceleration-stats.component';
|
||||
|
@ -160,6 +160,29 @@ export class ServicesApiServices {
|
|||
return this.httpClient.get<Acceleration[]>(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params } });
|
||||
}
|
||||
|
||||
getAllAccelerationHistory$(params: AccelerationHistoryParams, limit?: number, findTxid?: string): Observable<Acceleration[]> {
|
||||
const getPage$ = (page: number, accelerations: Acceleration[] = []): Observable<{ page: number, total: number, accelerations: Acceleration[] }> => {
|
||||
return this.getAccelerationHistoryObserveResponse$({...params, page}).pipe(
|
||||
map((response) => ({
|
||||
page,
|
||||
total: parseInt(response.headers.get('X-Total-Count'), 10),
|
||||
accelerations: accelerations.concat(response.body || []),
|
||||
})),
|
||||
switchMap(({page, total, accelerations}) => {
|
||||
if (accelerations.length >= Math.min(total, limit ?? Infinity) || (findTxid && accelerations.find((acc) => acc.txid === findTxid))) {
|
||||
return of({ page, total, accelerations });
|
||||
} else {
|
||||
return getPage$(page + 1, accelerations);
|
||||
}
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
return getPage$(1).pipe(
|
||||
map(({ accelerations }) => accelerations),
|
||||
);
|
||||
}
|
||||
|
||||
getAccelerationHistoryObserveResponse$(params: AccelerationHistoryParams): Observable<any> {
|
||||
return this.httpClient.get<any>(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params }, observe: 'response'});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue