Improve appstore listing speed
This commit is contained in:
+42
-48
@@ -376,40 +376,16 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$tran
|
||||
return;
|
||||
}
|
||||
|
||||
// start with all apps listing. this also sets $scope.apps accordingly
|
||||
$scope.showCategory('');
|
||||
|
||||
getSubscription(function (error) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
onSubscribed(function (error) { if (error) console.error(error); });
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function onSubscribed(callback) {
|
||||
// start with all apps listing. this also sets $scope.apps accordingly
|
||||
$scope.showCategory('');
|
||||
|
||||
// do this in background
|
||||
Client.refreshConfig(); // refresh domain, user, group limit etc
|
||||
fetchUsers();
|
||||
fetchGroups();
|
||||
|
||||
// domains is required since we populate the dropdown with domains[0]
|
||||
Client.getDomains(function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
$scope.domains = result;
|
||||
|
||||
// show install app dialog immediately if an app id was passed in the query
|
||||
// hashChangeListener calls $apply, so make sure we don't double digest here
|
||||
setTimeout(hashChangeListener, 1);
|
||||
|
||||
setTimeout(function () { $('#appstoreSearch').focus(); }, 1);
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
// TODO does not support testing apps in search
|
||||
$scope.search = function () {
|
||||
if (!$scope.searchString) return $scope.showCategory($scope.cachedCategory);
|
||||
@@ -576,6 +552,17 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$tran
|
||||
});
|
||||
}
|
||||
|
||||
function fetchMemory() {
|
||||
Client.memory(function (error, memory) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return $timeout(fetchMemory, 5000);
|
||||
}
|
||||
|
||||
$scope.memory = memory;
|
||||
});
|
||||
}
|
||||
|
||||
function getSubscription(callback) {
|
||||
Client.getSubscription(function (error, subscription) {
|
||||
if (error) {
|
||||
@@ -602,39 +589,46 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$tran
|
||||
}
|
||||
|
||||
function init() {
|
||||
$scope.ready = false;
|
||||
Client.getAppstoreAppsFast(function (error) {
|
||||
$scope.ready = true;
|
||||
|
||||
getSubscription(function (error) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
if (error && error.statusCode === 402) {
|
||||
$scope.validSubscription = false;
|
||||
return;
|
||||
} else if (error) {
|
||||
console.error('Failed to get apps. Will retry.', error);
|
||||
return $timeout(init, 1000);
|
||||
}
|
||||
|
||||
if (!$scope.validSubscription) { // show the login form
|
||||
$scope.ready = true;
|
||||
return;
|
||||
}
|
||||
$scope.validSubscription = true;
|
||||
|
||||
onSubscribed(function (error) {
|
||||
if (error) console.error(error);
|
||||
$scope.showCategory('');
|
||||
|
||||
$scope.ready = true;
|
||||
// refresh everything in background
|
||||
getSubscription(function (error) { if (error) console.error('Failed to get subscription.', error); });
|
||||
Client.getAppstoreApps(function (error) { if (error) console.error('Failed to fetch apps.', error); });
|
||||
Client.refreshConfig(); // refresh domain, user, group limit etc
|
||||
fetchUsers();
|
||||
fetchGroups();
|
||||
fetchMemory();
|
||||
|
||||
// domains is required since we populate the dropdown with domains[0]
|
||||
Client.getDomains(function (error, result) {
|
||||
if (error) return console.error('Error getting domains.', error);
|
||||
|
||||
$scope.domains = result;
|
||||
|
||||
// show install app dialog immediately if an app id was passed in the query
|
||||
// hashChangeListener calls $apply, so make sure we don't double digest here
|
||||
setTimeout(hashChangeListener, 1);
|
||||
|
||||
setTimeout(function () { $('#appstoreSearch').focus(); }, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// fetch early
|
||||
Client.onReady(function () { Client.getAppstoreApps(function () {}); });
|
||||
|
||||
Client.onReady(init);
|
||||
|
||||
Client.onReady(function () {
|
||||
Client.memory(function (error, memory) {
|
||||
if (error) console.error(error);
|
||||
$scope.memory = memory;
|
||||
});
|
||||
});
|
||||
|
||||
// note: do not use hide.bs.model since it is called immediately from switchToAppsView which is already in angular scope
|
||||
$('#appInstallModal').on('hidden.bs.modal', function () {
|
||||
// clear the appid and version in the search bar when dialog is cancelled
|
||||
|
||||
Reference in New Issue
Block a user