From 0c762c689374448408f6f03a08fb304e5a4f09fa Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Wed, 16 Oct 2019 09:30:49 +0000 Subject: [PATCH] [Monitor]: Restrict calls of number with the same source and url to once. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor@57382 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/monitor/monitor.component.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/monitor/monitor.component.ts b/src/app/monitor/monitor.component.ts index ecadc9d..8e95003 100644 --- a/src/app/monitor/monitor.component.ts +++ b/src/app/monitor/monitor.component.ts @@ -14,6 +14,7 @@ import {StakeholderService} from "../services/stakeholder.service"; import {Category, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; import {MenuItem, RootMenuItem, SideMenuItem} from "../openaireLibrary/sharedComponents/menu"; import {StatisticsService} from "../utils/services/statistics.service"; +import {response} from "express"; @Component({ selector: 'monitor', @@ -162,13 +163,26 @@ export class MonitorComponent { } private setIndicators() { + let urls: Map = new Map(); this.activeSubCategory.numbers.forEach((number, index) => { - this.statisticsService.getNumbers(number.indicatorPaths[0].source, number.indicatorPaths[0].url).subscribe(response => { - number.indicatorPaths[0].jsonPath.forEach(jsonPath => { - response = response[jsonPath]; + if(number.isActive && number.isPublic) { + const pair = JSON.stringify([number.indicatorPaths[0].source, number.indicatorPaths[0].url]); + const indexes = urls.get(pair) ? urls.get(pair) : []; + indexes.push(index); + urls.set(pair, indexes); + } + }); + urls.forEach((indexes, pair) => { + pair = JSON.parse(pair); + this.statisticsService.getNumbers(pair[0], pair[1]).subscribe( response => { + indexes.forEach( index => { + let result = JSON.parse(JSON.stringify(response)); + this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => { + result = result[jsonPath]; + }); + this.numberResults.set(index, result); }); - this.numberResults.set(index, response); - }); + }) }); this.activeSubCategory.charts.forEach((chart, index) => { if (chart.indicatorPaths.length > 0) {