Skip to content

Commit 79ea4cb

Browse files
committed
Correct N+1 utilization checking
1 parent 7f5485d commit 79ea4cb

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

resources/assets/scripts/components/dashboard/Dashboard.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@
6464
},
6565
6666
/**
67-
* Once the page is mounted set a function to run every 5 seconds that will
67+
* Once the page is mounted set a function to run every 10 seconds that will
6868
* iterate through the visible servers and fetch their resource usage.
6969
*/
7070
mounted: function () {
71-
this._iterateServerResourceUse();
71+
window.setTimeout(() => {
72+
this._iterateServerResourceUse();
73+
}, 5000);
7274
},
7375
7476
computed: {
@@ -133,9 +135,6 @@
133135
}
134136
135137
window.events.$emit(`server:${server.uuid}::resources`, response.data.attributes);
136-
})
137-
.catch(err => {
138-
console.error(err);
139138
});
140139
},
141140
@@ -144,12 +143,23 @@
144143
*
145144
* @private
146145
*/
147-
_iterateServerResourceUse: function (initialTimeout = 5000) {
148-
window.setTimeout(() => {
149-
if (this.documentVisible) {
150-
return window.setTimeout(this._iterateServerResourceUse(), 5000);
151-
}
152-
}, initialTimeout);
146+
_iterateServerResourceUse: function (loop = true) {
147+
// Try again in 10 seconds, window is not in the foreground.
148+
if (!this.documentVisible && loop) {
149+
window.setTimeout(() => {
150+
this._iterateServerResourceUse();
151+
}, 10000);
152+
}
153+
154+
this.servers.forEach(server => {
155+
this.getResourceUse(server);
156+
});
157+
158+
if (loop) {
159+
window.setTimeout(() => {
160+
this._iterateServerResourceUse();
161+
}, 10000);
162+
}
153163
},
154164
155165
/**
@@ -167,7 +177,9 @@
167177
// If it has been more than 30 seconds since this window was put into the background
168178
// lets go ahead and refresh all of the listed servers so that they have fresh stats.
169179
const diff = differenceInSeconds(new Date(), this.backgroundedAt);
170-
this._iterateServerResourceUse(diff > 30 ? 1 : 5000);
180+
if (diff > 30) {
181+
this._iterateServerResourceUse(false);
182+
}
171183
},
172184
}
173185
};

0 commit comments

Comments
 (0)