Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchKit - Prevent race conditions in search display loading #21394

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

// Trait provides base methods and properties common to all search display types
angular.module('crmSearchDisplay').factory('searchDisplayBaseTrait', function(crmApi4) {
var ts = CRM.ts('org.civicrm.search_kit');
var ts = CRM.ts('org.civicrm.search_kit'),
runCount = 0;

// Replace tokens keyed to rowData.
// Pass view=true to replace with view value, otherwise raw value is used.
Expand Down Expand Up @@ -77,7 +78,7 @@
$scope.$apply(function() {
ctrl.runSearch();
});
}, 100);
}, 800);

// If search is embedded in contact summary tab, display count in tab-header
var contactTab = $element.closest('.crm-contact-page .ui-tabs-panel').attr('id');
Expand Down Expand Up @@ -142,12 +143,16 @@
// Call SearchDisplay.run and update ctrl.results and ctrl.rowCount
runSearch: function(editedRow) {
var ctrl = this,
requestId = ++runCount;
apiParams = this.getApiParams();
this.loading = true;
_.each(ctrl.onPreRun, function(callback) {
callback.call(ctrl, apiParams);
});
return crmApi4('SearchDisplay', 'run', apiParams).then(function(results) {
if (requestId < runCount) {
return; // Another request started after this one
}
ctrl.results = results;
ctrl.editing = ctrl.loading = false;
if (!ctrl.rowCount) {
Expand All @@ -164,6 +169,9 @@
callback.call(ctrl, results, 'success', editedRow);
});
}, function(error) {
if (requestId < runCount) {
return; // Another request started after this one
}
ctrl.results = [];
ctrl.editing = ctrl.loading = false;
_.each(ctrl.onPostRun, function(callback) {
Expand Down