Removes user timeout timer to do digests, now just has it's own internal clock and the countdown timer will count for itself and only digest it's own scope, this is heaps better for performance.

This commit is contained in:
Shannon
2013-10-30 18:57:43 +11:00
parent 51aefd2b6b
commit bb5dad8c1d
2 changed files with 27 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
angular.module('umbraco.services')
.factory('userService', function ($rootScope, $q, $location, $log, securityRetryQueue, authResource, dialogService, $timeout) {
.factory('userService', function ($rootScope, $q, $location, $log, securityRetryQueue, authResource, dialogService, $timeout, angularHelper) {
var currentUser = null;
var lastUserId = null;
@@ -60,8 +60,8 @@ angular.module('umbraco.services')
this will continually count down their current remaining seconds every 2 seconds until
there are no more seconds remaining.
*/
function countdownUserTimeout() {
$timeout(function () {
function countdownUserTimeout() {
$timeout(function() {
if (currentUser) {
//countdown by 2 seconds since that is how long our timer is for.
currentUser.remainingAuthSeconds -= 2;
@@ -90,12 +90,17 @@ angular.module('umbraco.services')
countdownUserTimeout();
}
else {
//we are either timed out or very close to timing out so we need to show the login dialog.
userAuthExpired();
//NOTE: the safeApply because our timeout is set to not run digests (performance reasons)
angularHelper.safeApply($rootScope, function() {
userAuthExpired();
});
}
}
}, 2000);//every 2 seconds
}
}, 2000, //every 2 seconds
false); //false = do NOT execute a digest for every iteration
}
/** Called to update the current user's timeout */

View File

@@ -1,5 +1,5 @@
angular.module("umbraco")
.controller("Umbraco.Dialogs.UserController", function ($scope, $location, userService, historyService) {
.controller("Umbraco.Dialogs.UserController", function ($scope, $location, $timeout, userService, historyService) {
$scope.user = userService.getCurrentUser();
$scope.history = historyService.current;
@@ -13,5 +13,17 @@ angular.module("umbraco")
$scope.gotoHistory = function (link) {
$location.path(link);
$scope.hide();
};
});
};
//Manually update the remaining timeout seconds
function updateTimeout() {
$timeout(function () {
$scope.user = userService.getCurrentUser();
//manually execute the digest against this scope only
$scope.$digest();
updateTimeout(); //keep going (recurse)
}, 1000, false); // 1 second, do NOT execute a global digest
}
updateTimeout();
});