From c832464998ed3ed34af3bda37056dfdc1729f4a6 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Mon, 4 Jul 2022 12:33:36 +0200 Subject: [PATCH] mgr/dashboard: debounce reload data with serverSide 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 --- .../src/app/ceph/block/rbd-list/rbd-list.component.ts | 7 +++++-- .../src/app/shared/datatable/table/table.component.ts | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts index ea25dad289a9b..71d7121848695 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts @@ -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; } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts index 7808b833f99eb..2ee7ac78bf6dd 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts @@ -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. -- 2.39.5