From 85aa9565c2ca94a4e4575b1412bd08375113d1d0 Mon Sep 17 00:00:00 2001 From: Edwin Santizo Date: Mon, 3 Oct 2022 22:56:56 -0600 Subject: [PATCH] fixed bug were it would make multiple xhr requests found that with multiple subscribers to an observable it would remit the execution chain aka send xhr requests. We were using share method but share we were using it incorrectly. After reading the docs, shareReplay method allows for the replaying of values that was returned from the observable without making a costly xhr request for any amount of subscribres. --- ui/angular.json | 14 +++++++++++++- ui/src/app/abstract.service.ts | 6 +++--- ui/src/app/richskill/service/rich-skill.service.ts | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ui/angular.json b/ui/angular.json index 4962e3575..97af91553 100644 --- a/ui/angular.json +++ b/ui/angular.json @@ -87,6 +87,14 @@ "maximumError": "4kb" } ] + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true } } }, @@ -99,8 +107,12 @@ "configurations": { "production": { "browserTarget": "ui:build:production" + }, + "development": { + "browserTarget": "ui:build:development" } - } + }, + "defaultConfiguration": "development" }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", diff --git a/ui/src/app/abstract.service.ts b/ui/src/app/abstract.service.ts index e5c1d6918..33e9e4f43 100644 --- a/ui/src/app/abstract.service.ts +++ b/ui/src/app/abstract.service.ts @@ -6,7 +6,7 @@ import {ApiTaskResult, ITaskResult} from "./task/ApiTaskResult" import {PublishStatus} from "./PublishStatus" import {ApiSortOrder} from "./richskill/ApiSkill" import {ApiSearch} from "./richskill/service/rich-skill-search.service" -import {map, share} from "rxjs/operators" +import {map, share, shareReplay} from "rxjs/operators" import {Router} from "@angular/router" import {Location} from "@angular/common" @@ -56,7 +56,7 @@ export abstract class AbstractService { const observable = this.httpClient.get(this.buildUrl(path), { headers: this.wrapHeaders(headers), params, - observe: "response"}).pipe(share()) + observe: "response"}).pipe(shareReplay()) observable .subscribe(() => {}, (err) => { this.redirectToLogin(err) }) return observable @@ -65,7 +65,7 @@ export abstract class AbstractService { const observable = this.httpClient.post(this.buildUrl(path), body, { headers: this.wrapHeaders(headers), params, - observe: "response"}).pipe(share()) + observe: "response"}).pipe(shareReplay()) observable .subscribe(() => {}, (err) => { this.redirectToLogin(err) }) return observable diff --git a/ui/src/app/richskill/service/rich-skill.service.ts b/ui/src/app/richskill/service/rich-skill.service.ts index 10996bd2e..159811cbc 100644 --- a/ui/src/app/richskill/service/rich-skill.service.ts +++ b/ui/src/app/richskill/service/rich-skill.service.ts @@ -141,7 +141,6 @@ export class RichSkillService extends AbstractService { params, body: apiSearch, }) - .pipe(share()) .pipe(map(({body, headers}) => { const totalCount = Number(headers.get("X-Total-Count")) const skills = body?.map(skill => skill) || []