Ver Fonte

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.

Ed Dawley há 11 anos atrás
pai
commit
6152a5e3c2
1 ficheiros alterados com 11 adições e 0 exclusões
  1. 11 0
      src/app/controllers/search.js

+ 11 - 0
src/app/controllers/search.js

@@ -17,6 +17,7 @@ function (angular, _, config, $) {
       $scope.results = {dashboards: [], tags: [], metrics: []};
       $scope.query = { query: 'title:' };
       $scope.db = datasourceSrv.getGrafanaDB();
+      $scope.currentSearchId = 0;
 
       $timeout(function() {
         $scope.giveSearchFocus = $scope.giveSearchFocus + 1;
@@ -75,8 +76,18 @@ function (angular, _, config, $) {
     };
 
     $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)
         .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.results.dashboards = results.dashboards;
           $scope.results.tags = results.tags;