From: Martin Stockhammer Date: Mon, 11 Jan 2021 22:03:06 +0000 (+0100) Subject: Fixing multiple REST calls X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cc1c52b3d49dccd52a79779601c6639916d86339;p=archiva.git Fixing multiple REST calls --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts index f7d2188a8..6239e88d2 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts @@ -18,7 +18,17 @@ import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {concat, merge, Observable, of, Subject} from "rxjs"; -import {debounceTime, distinctUntilChanged, filter, map, pluck, startWith, switchMap} from "rxjs/operators"; +import { + debounceTime, + distinctUntilChanged, + filter, + map, + multicast, + pluck, + refCount, + startWith, + switchMap +} from "rxjs/operators"; import {EntityService} from "@app/model/entity-service"; import {FieldToggle} from "@app/model/field-toggle"; import {PageQuery} from "../model/page-query"; @@ -151,7 +161,7 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After } ngOnInit(): void { - // console.log("Pag Init " + this.id); + console.log("Pag Init " + this.id); // We combine the sources for the page and the search input field to a observable 'source' const pageSource = this.pageStream.pipe(map(pageNumber => { return new PageQuery(this.searchTerm, pageNumber); @@ -171,7 +181,11 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After this.service(params.search, (params.page - 1) * this.pageSize, this.pageSize, this.sortField, this.sortOrder) .pipe(map(pagedResult=>LoadingValue.finish>(pagedResult))) ) - ) + ), + // This is to avoid multiple REST calls, without each subscriber would + // cause a REST call. + multicast(new Subject()), + refCount() ); this.total$ = source.pipe(filter(val=>val.hasValue()),map(val=>val.value), pluck('pagination', 'total_count'));