Make the org and user views more performant by only loading teams and robots when requested, making some loads async, and skipping others entirely on mobile

This commit is contained in:
Joseph Schorr 2015-04-21 16:07:24 -04:00
parent 738c3efc4d
commit afa59da8d6
10 changed files with 52 additions and 18 deletions

View file

@ -10,7 +10,8 @@ angular.module('quay').directive('robotsManager', function () {
restrict: 'C',
scope: {
'organization': '=organization',
'user': '=user'
'user': '=user',
'isEnabled': '=isEnabled'
},
controller: function($scope, $element, ApiService, $routeParams, CreateService, Config) {
$scope.ROBOT_PATTERN = ROBOT_PATTERN;
@ -101,7 +102,7 @@ angular.module('quay').directive('robotsManager', function () {
var update = function() {
if (!$scope.user && !$scope.organization) { return; }
if ($scope.loading) { return; }
if ($scope.loading || !$scope.isEnabled) { return; }
$scope.loading = true;
ApiService.getRobots($scope.organization).then(function(resp) {
@ -117,6 +118,7 @@ angular.module('quay').directive('robotsManager', function () {
});
};
$scope.$watch('isEnabled', update);
$scope.$watch('organization', update);
$scope.$watch('user', update);
}

View file

@ -9,9 +9,10 @@ angular.module('quay').directive('teamsManager', function () {
transclude: false,
restrict: 'C',
scope: {
'organization': '=organization'
'organization': '=organization',
'isEnabled': '=isEnabled'
},
controller: function($scope, $element, ApiService, CreateService) {
controller: function($scope, $element, ApiService, CreateService, $timeout) {
$scope.TEAM_PATTERN = TEAM_PATTERN;
$scope.teamRoles = [
{ 'id': 'member', 'title': 'Member', 'kind': 'default' },
@ -23,11 +24,20 @@ angular.module('quay').directive('teamsManager', function () {
$scope.orderedTeams = [];
var loadTeamMembers = function() {
if (!$scope.organization) { return; }
if (!$scope.organization || !$scope.isEnabled) { return; }
// Skip loading team members on mobile.
if (!window.matchMedia('(min-width: 768px)').matches) {
return;
}
for (var name in $scope.organization.teams) {
if (!$scope.organization.teams.hasOwnProperty(name)) { continue; }
loadMembersOfTeam(name);
if (!$scope.organization.teams.hasOwnProperty(name) || $scope.members[name]) { continue; }
// Load fully async to prevent it from blocking the UI.
$timeout(function() {
loadMembersOfTeam(name);
}, 1);
}
};
@ -47,7 +57,9 @@ angular.module('quay').directive('teamsManager', function () {
};
var loadOrderedTeams = function() {
if (!$scope.organization || !$scope.organization.ordered_teams) { return; }
if (!$scope.organization || !$scope.organization.ordered_teams || !$scope.isEnabled) {
return;
}
$scope.orderedTeams = [];
$scope.organization.ordered_teams.map(function(name) {
@ -58,6 +70,9 @@ angular.module('quay').directive('teamsManager', function () {
$scope.$watch('organization', loadOrderedTeams);
$scope.$watch('organization', loadTeamMembers);
$scope.$watch('isEnabled', loadOrderedTeams);
$scope.$watch('isEnabled', loadTeamMembers);
$scope.setRole = function(role, teamname) {
var previousRole = $scope.organization.teams[teamname].role;
$scope.organization.teams[teamname].role = role;