fix api spam

This commit is contained in:
Daniel Ponte 2025-01-11 16:38:27 -05:00
parent 4d2eaefe1f
commit 185237cd01

View file

@ -33,7 +33,7 @@ export class TalkgroupService {
private subscriptions = new Subscription(); private subscriptions = new Subscription();
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
this.tgs$ = this.fetchAll.pipe(switchMap(() => this.getTalkgroups())); this.tgs$ = this.fetchAll.pipe(switchMap(() => this.getTalkgroups()));
this.tags$ = this.fetchAll.pipe(switchMap(() => this.getAllTags())); this.tags$ = this.fetchAll.pipe(switchMap(() => this.getAllTags()), shareReplay());
this.fillTgMap(); this.fillTgMap();
} }
@ -52,11 +52,8 @@ export class TalkgroupService {
getTalkgroup(sys: number, tg: number): Observable<Talkgroup> { getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {
const key = this.tgKey(sys, tg); const key = this.tgKey(sys, tg);
if (!this._getTalkgroup.get(key)) { if (!this._getTalkgroup.get(key)) {
return this.tgs$.pipe( let rs = new ReplaySubject<Talkgroup>();
switchMap((talkg) => this._getTalkgroup.set(key, rs);
talkg.filter((tgv) => tgv.tgid == tg && tgv.system_id == sys),
),
);
} }
return this._getTalkgroup.get(key)!; return this._getTalkgroup.get(key)!;
} }