Kaynağa Gözat

merged with master

Torkel Ödegaard 11 yıl önce
ebeveyn
işleme
15c1b48b25
2 değiştirilmiş dosya ile 16 ekleme ve 11 silme
  1. 1 0
      CHANGELOG.md
  2. 15 11
      src/app/services/dashboard/dashboardModel.js

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@ vNext
 - Series names and column name typeahead cache fix (Fixes #522)
 - Fixed influxdb issue with raw query that caused wrong value column detection (Fixes #504)
 - Default property that marks which datasource is default in config.js is now optional (Fixes #526)
+- Auto-refresh caused 2 refreshes (and hence mulitple queries) each time (at least in firefox) (Fixes #342)
 
 # 1.6.0 (2014-06-16)
 

+ 15 - 11
src/app/services/dashboard/dashboardModel.js

@@ -67,21 +67,25 @@ function (angular, $, kbn, _) {
       $rootScope.$broadcast('refresh');
     };
 
-    p.set_interval = function(interval) {
-      this.refresh = interval;
+    p.start_scheduled_refresh = function (after_ms) {
+      this.cancel_scheduled_refresh();
+      this.refresh_timer = timer.register($timeout(function () {
+        this.start_scheduled_refresh(after_ms);
+        this.emit_refresh();
+      }.bind(this), after_ms));
+    };
+
+    p.cancel_scheduled_refresh = function () {
+      timer.cancel(this.refresh_timer);
+    };
 
+    p.set_interval = function (interval) {
+      this.refresh = interval;
       if (interval) {
         var _i = kbn.interval_to_ms(interval);
-        timer.cancel(this.refresh_timer);
-        var self = this;
-
-        this.refresh_timer = timer.register($timeout(function() {
-          self.set_interval(interval);
-          self.emit_refresh();
-        },_i));
-        this.emit_refresh();
+        this.start_scheduled_refresh(_i);
       } else {
-        timer.cancel(this.refresh_timer);
+        this.cancel_scheduled_refresh();
       }
     };