diff options
author | Takuya Noguchi <tak.noguchi.iridge@gmail.com> | 2017-02-15 11:36:46 +0900 |
---|---|---|
committer | Takuya Noguchi <tak.noguchi.iridge@gmail.com> | 2017-02-25 19:54:16 +0900 |
commit | 2ab322ebc73186cdb595bc0a3c463975a5bc1903 (patch) | |
tree | 66e8d87bdbfcca556896f0847369582c93f8d23d | |
parent | 7d15f36be6cdefcf95a96bf4cbb425baceaf2488 (diff) | |
download | gitlab-ce-2ab322ebc73186cdb595bc0a3c463975a5bc1903.tar.gz |
Replace setInterval with setTimeout to prevent highly frequent requests
-rw-r--r-- | app/assets/javascripts/build.js | 33 | ||||
-rw-r--r-- | changelogs/unreleased/28212-avoid-dos-on-build-trace.yml | 4 |
2 files changed, 24 insertions, 13 deletions
diff --git a/app/assets/javascripts/build.js b/app/assets/javascripts/build.js index 8fa1aceddff..d1883f51d47 100644 --- a/app/assets/javascripts/build.js +++ b/app/assets/javascripts/build.js @@ -7,7 +7,7 @@ var DOWN_BUILD_TRACE = '#down-build-trace'; this.Build = (function() { - Build.interval = null; + Build.timeout = null; Build.state = null; @@ -31,7 +31,7 @@ this.$scrollBottomBtn = $('#scroll-bottom'); this.$buildRefreshAnimation = $('.js-build-refresh'); - clearInterval(Build.interval); + clearTimeout(Build.timeout); // Init breakpoint checker this.bp = Breakpoints.get(); @@ -52,17 +52,7 @@ this.getInitialBuildTrace(); this.initScrollButtonAffix(); } - if (this.buildStatus === "running" || this.buildStatus === "pending") { - Build.interval = setInterval((function(_this) { - // Check for new build output if user still watching build page - // Only valid for runnig build when output changes during time - return function() { - if (_this.location() === _this.pageUrl) { - return _this.getBuildTrace(); - } - }; - })(this), 4000); - } + this.invokeBuildTrace(); } Build.prototype.initSidebar = function() { @@ -75,6 +65,22 @@ return window.location.href.split("#")[0]; }; + Build.prototype.invokeBuildTrace = function() { + var continueRefreshStatuses = ['running', 'pending']; + // Continue to update build trace when build is running or pending + if (continueRefreshStatuses.indexOf(this.buildStatus) !== -1) { + // Check for new build output if user still watching build page + // Only valid for runnig build when output changes during time + Build.timeout = setTimeout((function(_this) { + return function() { + if (_this.location() === _this.pageUrl) { + return _this.getBuildTrace(); + } + }; + })(this), 4000); + } + }; + Build.prototype.getInitialBuildTrace = function() { var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped']; @@ -105,6 +111,7 @@ if (log.state) { _this.state = log.state; } + _this.invokeBuildTrace(); if (log.status === "running") { if (log.append) { $('.js-build-output').append(log.html); diff --git a/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml b/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml new file mode 100644 index 00000000000..800e0389c86 --- /dev/null +++ b/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml @@ -0,0 +1,4 @@ +--- +title: Replace setInterval with setTimeout to prevent highly frequent requests +merge_request: 9271 +author: Takuya Noguchi |