Skip to content

Commit

Permalink
Merge pull request #1467 from dudleycarr/fix-run-away-counter
Browse files Browse the repository at this point in the history
nsqadmin: fix counter view
  • Loading branch information
jehiah authored Oct 25, 2023
2 parents 9a8c304 + 1f116a9 commit 30998dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nsqadmin/static/build/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nsqadmin/static/build/main.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions nsqadmin/static/js/views/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ var CounterView = BaseView.extend({

initialize: function() {
BaseView.prototype.initialize.apply(this, arguments);
this.listenTo(AppState, 'change:graph_interval', this.render);
this.listenTo(AppState, 'change:graph_interval', function() {
clearTimeout(this.poller);
clearTimeout(this.animator);
this.render();
this.start();
});
this.start();
},

Expand All @@ -29,6 +34,7 @@ var CounterView = BaseView.extend({
this.looping = false;
this.targetPollInterval = 10000;
this.currentNum = -1;
this.lastNum = 0;
this.interval = 100;
this.graphUrl = null;
this.updateStats();
Expand All @@ -52,16 +58,17 @@ var CounterView = BaseView.extend({
if (this.currentNum === -1) {
// seed the display
this.currentNum = num;
this.lastNum = num;
this.writeCounts(this.currentNum);
} else if (num > this.lastNum) {
var delta = num - this.lastNum;
this.delta = (delta / (this.interval / 1000)) / 50;
this.lastNum = num;

if (!this.animator) {
this.displayFrame();
}
}
this.currentNum = this.lastNum;
this.lastNum = num;

var newInterval = this.interval;
if (newInterval < this.targetPollInterval) {
Expand Down Expand Up @@ -97,9 +104,13 @@ var CounterView = BaseView.extend({
},

displayFrame: function() {
this.currentNum += this.delta;
this.currentNum = Math.min(this.currentNum + this.delta, this.lastNum)
this.writeCounts(this.currentNum);
this.animator = setTimeout(this.displayFrame.bind(this), 1000 / 60);
if (this.currentNum < this.lastNum) {
this.animator = setTimeout(this.displayFrame.bind(this), 1000 / 60);
} else {
this.animator = null;
}
},

writeCounts: function(c) {
Expand Down

0 comments on commit 30998dd

Please sign in to comment.