Commit 6152a5e3 by Ed Dawley

Adding in global search id counter so that async search responses can be…

Adding in global search id counter so that async search responses can be discarded if a newer search is being processed.  This prevents older search results from clobbering a newer search that happened to complete faster.
parent 3df592c7
...@@ -17,6 +17,7 @@ function (angular, _, config, $) { ...@@ -17,6 +17,7 @@ function (angular, _, config, $) {
$scope.results = {dashboards: [], tags: [], metrics: []}; $scope.results = {dashboards: [], tags: [], metrics: []};
$scope.query = { query: 'title:' }; $scope.query = { query: 'title:' };
$scope.db = datasourceSrv.getGrafanaDB(); $scope.db = datasourceSrv.getGrafanaDB();
$scope.currentSearchId = 0;
$timeout(function() { $timeout(function() {
$scope.giveSearchFocus = $scope.giveSearchFocus + 1; $scope.giveSearchFocus = $scope.giveSearchFocus + 1;
...@@ -75,8 +76,18 @@ function (angular, _, config, $) { ...@@ -75,8 +76,18 @@ function (angular, _, config, $) {
}; };
$scope.searchDashboards = function(queryString) { $scope.searchDashboards = function(queryString) {
// bookeeping for determining stale search requests
var searchId = $scope.currentSearchId + 1;
$scope.currentSearchId = searchId > $scope.currentSearchId ? searchId : $scope.currentSearchId;
return $scope.db.searchDashboards(queryString) return $scope.db.searchDashboards(queryString)
.then(function(results) { .then(function(results) {
// since searches are async, it's possible that these results are not for the latest search. throw
// them away if so
if (searchId < $scope.currentSearchId) {
return;
}
$scope.tagsOnly = results.tagsOnly; $scope.tagsOnly = results.tagsOnly;
$scope.results.dashboards = results.dashboards; $scope.results.dashboards = results.dashboards;
$scope.results.tags = results.tags; $scope.results.tags = results.tags;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment