fix memory leak in output render service

This commit is contained in:
Jake McDermott
2018-06-05 09:33:35 -04:00
parent 429c1bf2b4
commit 1c414789fb
2 changed files with 47 additions and 38 deletions

View File

@@ -2,6 +2,7 @@ let $compile;
let $filter; let $filter;
let $q; let $q;
let $scope; let $scope;
let $state;
let page; let page;
let render; let render;
@@ -19,6 +20,7 @@ function JobsIndexController (
_$filter_, _$filter_,
_$q_, _$q_,
_$scope_, _$scope_,
_$state_,
_resource_, _resource_,
_page_, _page_,
_scroll_, _scroll_,
@@ -33,6 +35,7 @@ function JobsIndexController (
$filter = _$filter_; $filter = _$filter_;
$q = _$q_; $q = _$q_;
$scope = _$scope_; $scope = _$scope_;
$state = _$state_;
resource = _resource_; resource = _resource_;
page = _page_; page = _page_;
@@ -352,19 +355,9 @@ function devClear () {
render.clear().then(() => init()); render.clear().then(() => init());
} }
// function showHostDetails (id) { function showHostDetails (id, uuid) {
// jobEvent.request('get', id) $state.go('output.host-event.json', { eventId: id, taskUuid: uuid });
// .then(() => { }
// const title = jobEvent.get('host_name');
// vm.host = {
// menu: true,
// stdout: jobEvent.get('stdout')
// };
// $scope.jobs.modal.show(title);
// });
// }
// function toggle (uuid, menu) { // function toggle (uuid, menu) {
// const lines = $(`.child-of-${uuid}`); // const lines = $(`.child-of-${uuid}`);
@@ -397,6 +390,7 @@ JobsIndexController.$inject = [
'$filter', '$filter',
'$q', '$q',
'$scope', '$scope',
'$state',
'resource', 'resource',
'JobPageService', 'JobPageService',
'JobScrollService', 'JobScrollService',

View File

@@ -30,11 +30,13 @@ const re = new RegExp(pattern);
const hasAnsi = input => re.test(input); const hasAnsi = input => re.test(input);
function JobRenderService ($q, $sce, $window) { function JobRenderService ($q, $sce, $window) {
this.init = ({ compile, isStreamActive }) => { this.init = ({ compile }) => {
this.parent = null; this.parent = null;
this.record = {}; this.record = {};
this.el = $(ELEMENT_TBODY); this.el = $(ELEMENT_TBODY);
this.hooks = { isStreamActive, compile }; this.hooks = { compile };
this.createToggles = false;
}; };
this.sortByLineNumber = (a, b) => { this.sortByLineNumber = (a, b) => {
@@ -55,12 +57,11 @@ function JobRenderService ($q, $sce, $window) {
events.sort(this.sortByLineNumber); events.sort(this.sortByLineNumber);
events.forEach(event => { for (let i = 0; i < events.length; ++i) {
const line = this.transformEvent(event); const line = this.transformEvent(events[i]);
html += line.html; html += line.html;
lines += line.count; lines += line.count;
}); }
return { html, lines }; return { html, lines };
}; };
@@ -177,13 +178,13 @@ function JobRenderService ($q, $sce, $window) {
} }
if (current) { if (current) {
if (!this.hooks.isStreamActive() && current.isParent && current.line === ln) { if (this.createToggles && current.isParent && current.line === ln) {
id = current.uuid; id = current.uuid;
tdToggle = `<td class="at-Stdout-toggle" ng-click="vm.toggle('${id}')"><i class="fa fa-angle-down can-toggle"></i></td>`; tdToggle = `<td class="at-Stdout-toggle" ng-click="vm.toggle('${id}')"><i class="fa fa-angle-down can-toggle"></i></td>`;
} }
if (current.isHost) { if (current.isHost) {
tdEvent = `<td class="at-Stdout-event--host" ui-sref="output.host-event.json({eventId: ${current.id}, taskUuid: '${current.uuid}' })"><span ng-non-bindable>${content}</span></td>`; tdEvent = `<td class="at-Stdout-event--host" ng-click="vm.showHostDetails('${current.id}', '${current.uuid}')">${content}</td>`;
} }
if (current.time && current.line === ln) { if (current.time && current.line === ln) {
@@ -239,18 +240,7 @@ function JobRenderService ($q, $sce, $window) {
return list; return list;
}; };
this.insert = (events, insert) => { this.remove = elements => this.requestAnimationFrame(() => elements.remove());
const result = this.transformEventGroup(events);
const html = this.trustHtml(result.html);
return this.requestAnimationFrame(() => insert(html))
.then(() => this.compile(html))
.then(() => result.lines);
};
this.remove = elements => this.requestAnimationFrame(() => {
elements.remove();
});
this.requestAnimationFrame = fn => $q(resolve => { this.requestAnimationFrame = fn => $q(resolve => {
$window.requestAnimationFrame(() => { $window.requestAnimationFrame(() => {
@@ -262,9 +252,8 @@ function JobRenderService ($q, $sce, $window) {
}); });
}); });
this.compile = html => { this.compile = content => {
html = $(this.el); this.hooks.compile(content);
this.hooks.compile(html);
return this.requestAnimationFrame(); return this.requestAnimationFrame();
}; };
@@ -286,9 +275,35 @@ function JobRenderService ($q, $sce, $window) {
return this.remove(elements); return this.remove(elements);
}; };
this.prepend = events => this.insert(events, html => this.el.prepend(html)); this.prepend = events => {
if (events.length < 1) {
return $q.resolve();
}
this.append = events => this.insert(events, html => this.el.append(html)); const result = this.transformEventGroup(events);
const html = this.trustHtml(result.html);
const newElements = angular.element(html);
return this.requestAnimationFrame(() => this.el.prepend(newElements))
.then(() => this.compile(newElements))
.then(() => result.lines);
};
this.append = events => {
if (events.length < 1) {
return $q.resolve();
}
const result = this.transformEventGroup(events);
const html = this.trustHtml(result.html);
const newElements = angular.element(html);
return this.requestAnimationFrame(() => this.el.append(newElements))
.then(() => this.compile(newElements))
.then(() => result.lines);
};
this.trustHtml = html => $sce.getTrustedHtml($sce.trustAsHtml(html)); this.trustHtml = html => $sce.getTrustedHtml($sce.trustAsHtml(html));