From bb5dad8c1d24d04949da17ea03152e52bdfb30bb Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 30 Oct 2013 18:57:43 +1100 Subject: [PATCH] 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. --- .../src/common/services/user.service.js | 19 ++++++++++++------- .../views/common/dialogs/user.controller.js | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js index 1808d30660..06cc7289b3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js @@ -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 */ diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js index ceac0f36f4..877ad7d351 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js @@ -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(); - }; -}); \ No newline at end of file + }; + + //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(); + + }); \ No newline at end of file