]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix token status being polled continously 57986/head
authorNizamudeen A <nia@redhat.com>
Wed, 12 Jun 2024 06:58:05 +0000 (12:28 +0530)
committerNizamudeen A <nia@redhat.com>
Tue, 25 Jun 2024 06:03:24 +0000 (11:33 +0530)
subscribe only once rather than continously subscribing

Fixes: https://tracker.ceph.com/issues/66665
Signed-off-by: Nizamudeen A <nia@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts

index 5a03abd22ff74751c729537ba62e7928364f0c93..55d7d2b6c39c7e9678e765b92eeb8ec8915c3c62 100644 (file)
@@ -2,7 +2,7 @@ import { HttpClient, HttpParams } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { BehaviorSubject, Observable, Subscription } from 'rxjs';
 import { TimerService } from '../services/timer.service';
-import { filter } from 'rxjs/operators';
+import { filter, first } from 'rxjs/operators';
 import { SummaryService } from '../services/summary.service';
 import { Router } from '@angular/router';
 
@@ -48,7 +48,7 @@ export class MultiClusterService {
 
   startClusterTokenStatusPolling() {
     let clustersTokenMap = new Map<string, { token: string; user: string }>();
-    const dataSubscription = this.subscribe((resp: any) => {
+    const dataSubscription = this.subscribeOnce((resp: any) => {
       const clustersConfig = resp['config'];
       let tempMap = new Map<string, { token: string; user: string }>();
       if (clustersConfig) {
@@ -92,13 +92,22 @@ export class MultiClusterService {
   }
 
   refreshTokenStatus() {
-    this.subscribe((resp: any) => {
+    this.subscribeOnce((resp: any) => {
       const clustersConfig = resp['config'];
       let tempMap = this.getTempMap(clustersConfig);
       return this.checkTokenStatus(tempMap).subscribe(this.getClusterTokenStatusObserver());
     });
   }
 
+  subscribeOnce(next: (data: any) => void, error?: (error: any) => void) {
+    return this.msData$
+      .pipe(
+        filter((value) => !!value),
+        first()
+      )
+      .subscribe(next, error);
+  }
+
   subscribe(next: (data: any) => void, error?: (error: any) => void) {
     return this.msData$.pipe(filter((value) => !!value)).subscribe(next, error);
   }