Be more efficient when polling for build status in the repo view

This commit is contained in:
Joseph Schorr 2015-04-22 13:33:20 -04:00
parent d4b9ebf4b9
commit 2128e39d77

View file

@ -75,7 +75,7 @@
loadImages();
// Track builds.
buildPollChannel = AngularPollChannel.create($scope, loadRepositoryBuilds, 5000 /* 5s */);
buildPollChannel = AngularPollChannel.create($scope, loadRepositoryBuilds, 15000 /* 15s */);
buildPollChannel.start();
}, 10);
});
@ -102,6 +102,26 @@
};
$scope.repositoryBuildsResource = ApiService.getRepoBuildsAsResource(params, /* background */true).get(function(resp) {
// Note: We could just set the builds here, but that causes a full digest cycle. Therefore,
// to be more efficient, we do some work here to determine if anything has changed since
// the last build load in the common case.
if ($scope.viewScope.builds && resp.builds.length == $scope.viewScope.builds.length) {
var hasNewInformation = false;
for (var i = 0; i < resp.builds.length; ++i) {
var current = $scope.viewScope.builds[i];
var updated = resp.builds[i];
if (current.phase != updated.phase || current.id != updated.id) {
hasNewInformation = true;
break;
}
}
if (!hasNewInformation) {
callback(true);
return;
}
}
$scope.viewScope.builds = resp.builds;
callback(true);
}, errorHandler);