From 27308fa519795addc09600d357c78ee116a742ba Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Mon, 23 Jan 2023 18:17:11 +0000 Subject: [PATCH] Speed up searchkit but preserve search filter behaviour --- ext/search_kit/ang/crmSearchDisplay/Pager.html | 2 +- .../traits/searchDisplayBaseTrait.service.js | 18 ++++++++++++------ .../searchDisplaySortableTrait.service.js | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/search_kit/ang/crmSearchDisplay/Pager.html b/ext/search_kit/ang/crmSearchDisplay/Pager.html index 5c35f17c88..44e97e59ea 100644 --- a/ext/search_kit/ang/crmSearchDisplay/Pager.html +++ b/ext/search_kit/ang/crmSearchDisplay/Pager.html @@ -9,7 +9,7 @@ boundary-links="true" total-items="$ctrl.rowCount" ng-model="$ctrl.page" - ng-change="$ctrl.getResults()" + ng-change="$ctrl.getResultsPronto()" items-per-page="$ctrl.limit" max-size="6" force-ellipses="true" diff --git a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js index 74c44df727..11b28f64e5 100644 --- a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js +++ b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js @@ -27,8 +27,14 @@ this.placeholders.push({}); } - // _.debounce used here to trigger the initial search immediately but prevent subsequent launches within 800ms - this.getResults = _.debounce(ctrl.runSearch, 800, {leading: true, trailing: false}); + // _.debounce used here to trigger the initial search immediately but prevent subsequent launches within 300ms + this.getResultsPronto = _.debounce(ctrl.runSearch, 300, {leading: true, trailing: false}); + // _.debounce used here to schedule a search if nothing else happens for 600ms: useful for auto-searching on typing + this.getResultsSoon = _.debounce(function() { + $scope.$apply(function() { + ctrl.runSearch(); + }); + }, 600); // Update totalCount variable if used. // Integrations can pass in `total-count="somevar" to keep track of the number of results returned @@ -50,7 +56,7 @@ // Popup forms in this display or surrounding Afform trigger a refresh $element.closest('form').on('crmPopupFormSuccess', function() { ctrl.rowCount = null; - ctrl.getResults(); + ctrl.getResultsPronto(); }); function onChangeFilters() { @@ -60,7 +66,7 @@ callback.call(ctrl); }); if (!ctrl.settings.button) { - ctrl.getResults(); + ctrl.getResultsSoon(); } } @@ -68,7 +74,7 @@ ctrl.page = 1; // Only refresh if search has already been run if (ctrl.results) { - ctrl.getResults(); + ctrl.getResultsPronto(); } } @@ -128,7 +134,7 @@ onClickSearchButton: function() { this.rowCount = null; this.page = 1; - this.getResults(); + this.getResultsPronto(); }, // Call SearchDisplay.run and update ctrl.results and ctrl.rowCount diff --git a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplaySortableTrait.service.js b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplaySortableTrait.service.js index c8f4faaa68..47a1f6bece 100644 --- a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplaySortableTrait.service.js +++ b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplaySortableTrait.service.js @@ -37,7 +37,7 @@ this.sort.push([col.key, dir]); } if (this.results || !this.settings.button) { - this.getResults(); + this.getResultsPronto(); } } -- 2.25.1