]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: debounce reload data with serverSide
authorPere Diaz Bou <pdiazbou@redhat.com>
Mon, 4 Jul 2022 10:33:36 +0000 (12:33 +0200)
committerPere Diaz Bou <pdiazbou@redhat.com>
Tue, 12 Jul 2022 17:09:02 +0000 (19:09 +0200)
Whenever we use serverSide (paginate through backend) we should
debounce reloadData since it might call api calls too much times.

Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

index ea25dad289a9b02aae40707fdd41373e1a28fe2c..71d71218486959b9c4d42676c598194ae32a804d 100644 (file)
@@ -398,8 +398,11 @@ export class RbdListComponent extends ListWithDetails implements OnInit {
       }
     });
 
-    this.count = CdTableServerSideService.getCount(resp[0]);
-    this.images = images;
+    if (images.length > 0) {
+      this.count = CdTableServerSideService.getCount(resp[0]);
+    } else {
+      this.count = 0;
+    }
     return images;
   }
 
index 7808b833f99eb1540800b9f3162942496fe5c28c..2ee7ac78bf6ddbb02d3964e093b5fd7d16c7a938 100644 (file)
@@ -266,6 +266,11 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
 
   ngOnInit() {
     this.localColumns = _.clone(this.columns);
+    // debounce reloadData method so that search doesn't run api requests
+    // for every keystroke
+    if (this.serverSide) {
+      this.reloadData = _.debounce(this.reloadData, 1000);
+    }
 
     // ngx-datatable triggers calculations each time mouse enters a row,
     // this will prevent that.