Fix bug in entity search that caused all robots and teams to be non-lazy loaded
Should help immensely with repository page load time Fixes https://coreosdev.atlassian.net/browse/QS-30
This commit is contained in:
parent
459d0ccd44
commit
ff3dac613a
2 changed files with 59 additions and 25 deletions
|
@ -44,7 +44,9 @@ angular.module('quay').directive('entitySearch', function () {
|
|||
'pullRight': '@pullRight'
|
||||
},
|
||||
controller: function($rootScope, $scope, $element, Restangular, UserService, ApiService, UtilService, AvatarService, Config) {
|
||||
$scope.lazyLoading = true;
|
||||
$scope.requiresLazyLoading = true;
|
||||
$scope.isLazyLoading = false;
|
||||
$scope.userRequestedLazyLoading = false;
|
||||
|
||||
$scope.teams = null;
|
||||
$scope.page = {};
|
||||
|
@ -67,37 +69,67 @@ angular.module('quay').directive('entitySearch', function () {
|
|||
return $.inArray(kind, opt_array || $scope.allowedEntities || ['user', 'team', 'robot']) >= 0;
|
||||
};
|
||||
|
||||
var resetCache = function() {
|
||||
$scope.requiresLazyLoading = true;
|
||||
|
||||
$scope.teams = null;
|
||||
$scope.page.robots = null;
|
||||
};
|
||||
|
||||
$scope.lazyLoad = function() {
|
||||
if (!$scope.namespace || !$scope.thisUser || !$scope.lazyLoading) { return; }
|
||||
$scope.userRequestedLazyLoading = true;
|
||||
$scope.checkLazyLoad();
|
||||
};
|
||||
|
||||
$scope.checkLazyLoad = function() {
|
||||
if (!$scope.namespace || !$scope.thisUser || !$scope.requiresLazyLoading ||
|
||||
$scope.isLazyLoading || !$scope.userRequestedLazyLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.isLazyLoading = true;
|
||||
$scope.isAdmin = UserService.isNamespaceAdmin($scope.namespace);
|
||||
$scope.isOrganization = !!UserService.getOrganization($scope.namespace);
|
||||
|
||||
|
||||
// Reset the cached teams and robots.
|
||||
// Reset the cached teams and robots, just to be sure.
|
||||
$scope.teams = null;
|
||||
$scope.page.robots = null;
|
||||
|
||||
var requiredOperations = 0;
|
||||
var operationComplete = function() {
|
||||
requiredOperations--;
|
||||
if (requiredOperations <= 0) {
|
||||
$scope.isLazyLoading = false;
|
||||
$scope.requiresLazyLoading = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Load the organization's teams (if applicable).
|
||||
if ($scope.isOrganization && isSupported('team')) {
|
||||
// Note: We load the org here again so that we always have the fully up-to-date
|
||||
requiredOperations++;
|
||||
|
||||
// Note: We load the org here directly so that we always have the fully up-to-date
|
||||
// teams list.
|
||||
ApiService.getOrganization(null, {'orgname': $scope.namespace}).then(function(resp) {
|
||||
$scope.teams = Object.keys(resp.teams).map(function(key) {
|
||||
return resp.teams[key];
|
||||
});
|
||||
});
|
||||
operationComplete();
|
||||
}, operationComplete);
|
||||
}
|
||||
|
||||
// Load the user/organization's robots (if applicable).
|
||||
if ($scope.isAdmin && isSupported('robot')) {
|
||||
requiredOperations++;
|
||||
|
||||
ApiService.getRobots($scope.isOrganization ? $scope.namespace : null).then(function(resp) {
|
||||
$scope.page.robots = resp.robots;
|
||||
$scope.lazyLoading = false;
|
||||
}, function() {
|
||||
$scope.lazyLoading = false;
|
||||
});
|
||||
} else {
|
||||
$scope.lazyLoading = false;
|
||||
operationComplete();
|
||||
}, operationComplete);
|
||||
}
|
||||
|
||||
if (requiredOperations == 0) {
|
||||
operationComplete();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -362,13 +394,15 @@ angular.module('quay').directive('entitySearch', function () {
|
|||
|
||||
$scope.$watch('namespace', function(namespace) {
|
||||
if (!namespace) { return; }
|
||||
$scope.lazyLoad();
|
||||
resetCache();
|
||||
$scope.checkLazyLoad();
|
||||
});
|
||||
|
||||
UserService.updateUserIn($scope, function(currentUser){
|
||||
if (currentUser.anonymous) { return; }
|
||||
$scope.thisUser = currentUser;
|
||||
$scope.lazyLoad();
|
||||
resetCache();
|
||||
$scope.checkLazyLoad();
|
||||
});
|
||||
|
||||
$scope.$watch('currentEntity', function(entity) {
|
||||
|
|
Reference in a new issue