diff --git a/searchPages/searchUtils/newSearchPage.component.ts b/searchPages/searchUtils/newSearchPage.component.ts index 3335bf93..be34dfef 100644 --- a/searchPages/searchUtils/newSearchPage.component.ts +++ b/searchPages/searchUtils/newSearchPage.component.ts @@ -218,7 +218,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { } } if (typeof document !== 'undefined') { - this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => { + this.subscriptions.push(this.indexInfoService.lastIndexDate.subscribe(lastIndexUpdate => { if (lastIndexUpdate) { this.indexUpdateDate = new Date(lastIndexUpdate); } diff --git a/utils/indexInfo.service.ts b/utils/indexInfo.service.ts index 1570a7e2..f81b1019 100644 --- a/utils/indexInfo.service.ts +++ b/utils/indexInfo.service.ts @@ -1,21 +1,34 @@ import {Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {EnvProperties} from './properties/env-properties'; -import {Observable, of} from "rxjs"; +import {BehaviorSubject, Observable, of} from "rxjs"; import {catchError, map} from "rxjs/operators"; +import {properties} from "../../../environments/environment"; @Injectable({ providedIn: "root" }) export class IndexInfoService { + private lastIndexDateSubject: BehaviorSubject = new BehaviorSubject(null); constructor(private http: HttpClient) { } - getLastIndexDate(properties: EnvProperties): Observable { - let url = properties.indexInfoAPI; - return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => res['claim_load_date'])).pipe(catchError(err => {return of(null)})); + get lastIndexDate(): Observable { + return this.lastIndexDateSubject.getValue() ? this.lastIndexDateSubject.asObservable() : this.getLastIndexDate(); + } + + setLastIndexDate(value: any) { + this.lastIndexDateSubject.next(value); + } + + getLastIndexDate(props: EnvProperties = properties): Observable { + let url = props.indexInfoAPI; + return this.http.get((props.useLongCache)? (props.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => { + this.setLastIndexDate(res['claim_load_date']); + return res['claim_load_date']; + })).pipe(catchError(err => {return of(null)})); } getStatsLastDate(properties: EnvProperties): Observable { let url = properties.indexInfoAPI;