Merge pull request #5485 from mempool/mononaut/paginated-accel-history
Handle paginated acceleration results
This commit is contained in:
		
						commit
						c4b90c2a18
					
				| @ -137,7 +137,7 @@ export class BlockPreviewComponent implements OnInit, OnDestroy { | |||||||
|                 }) |                 }) | ||||||
|               ), |               ), | ||||||
|             this.stateService.env.ACCELERATOR === true && block.height > 819500 |             this.stateService.env.ACCELERATOR === true && block.height > 819500 | ||||||
|               ? this.servicesApiService.getAccelerationHistory$({ blockHeight: block.height }) |               ? this.servicesApiService.getAllAccelerationHistory$({ blockHeight: block.height }) | ||||||
|                 .pipe(catchError(() => { |                 .pipe(catchError(() => { | ||||||
|                   return of([]); |                   return of([]); | ||||||
|                 })) |                 })) | ||||||
|  | |||||||
| @ -319,7 +319,7 @@ export class BlockComponent implements OnInit, OnDestroy { | |||||||
|     this.accelerationsSubscription = this.block$.pipe( |     this.accelerationsSubscription = this.block$.pipe( | ||||||
|       switchMap((block) => { |       switchMap((block) => { | ||||||
|         return this.stateService.env.ACCELERATOR === true && block.height > 819500 |         return this.stateService.env.ACCELERATOR === true && block.height > 819500 | ||||||
|           ? this.servicesApiService.getAccelerationHistory$({ blockHeight: block.height }) |           ? this.servicesApiService.getAllAccelerationHistory$({ blockHeight: block.height }) | ||||||
|             .pipe(catchError(() => { |             .pipe(catchError(() => { | ||||||
|               return of([]); |               return of([]); | ||||||
|             })) |             })) | ||||||
|  | |||||||
| @ -286,7 +286,7 @@ export class TrackerComponent implements OnInit, OnDestroy { | |||||||
|         this.accelerationInfo = null; |         this.accelerationInfo = null; | ||||||
|       }), |       }), | ||||||
|       switchMap((blockHash: string) => { |       switchMap((blockHash: string) => { | ||||||
|         return this.servicesApiService.getAccelerationHistory$({ blockHash }); |         return this.servicesApiService.getAllAccelerationHistory$({ blockHash }, null, this.txId); | ||||||
|       }), |       }), | ||||||
|       catchError(() => { |       catchError(() => { | ||||||
|         return of(null); |         return of(null); | ||||||
|  | |||||||
| @ -343,7 +343,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { | |||||||
|         this.setIsAccelerated(); |         this.setIsAccelerated(); | ||||||
|       }), |       }), | ||||||
|       switchMap((blockHeight: number) => { |       switchMap((blockHeight: number) => { | ||||||
|         return this.servicesApiService.getAccelerationHistory$({ blockHeight }).pipe( |         return this.servicesApiService.getAllAccelerationHistory$({ blockHeight }, null, this.txId).pipe( | ||||||
|           switchMap((accelerationHistory: Acceleration[]) => { |           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
 |             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'); |               return throwError('retry'); | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ import { HttpClient } from '@angular/common/http'; | |||||||
| import { StateService } from './state.service'; | import { StateService } from './state.service'; | ||||||
| import { StorageService } from './storage.service'; | import { StorageService } from './storage.service'; | ||||||
| import { MenuGroup } from '../interfaces/services.interface'; | 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 { IBackendInfo } from '../interfaces/websocket.interface'; | ||||||
| import { Acceleration, AccelerationHistoryParams } from '../interfaces/node-api.interface'; | import { Acceleration, AccelerationHistoryParams } from '../interfaces/node-api.interface'; | ||||||
| import { AccelerationStats } from '../components/acceleration/acceleration-stats/acceleration-stats.component'; | 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 } }); |     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> { |   getAccelerationHistoryObserveResponse$(params: AccelerationHistoryParams): Observable<any> { | ||||||
|     return this.httpClient.get<any>(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params }, observe: 'response'}); |     return this.httpClient.get<any>(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params }, observe: 'response'}); | ||||||
|   } |   } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user