You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2016/03/20 03:22:09 UTC

[29/50] incubator-guacamole-client git commit: GUAC-1378: Cache previous calls to $templateRequest() to avoid duplicating patch processing work.

GUAC-1378: Cache previous calls to $templateRequest() to avoid duplicating patch processing work.

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/8f17e9ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/8f17e9ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/8f17e9ed

Branch: refs/heads/master
Commit: 8f17e9ed0a1529c6bae380b691181a0b22e73e03
Parents: f2a767f
Author: Michael Jumper <mi...@guac-dev.org>
Authored: Thu Feb 18 17:49:48 2016 -0800
Committer: Michael Jumper <mi...@guac-dev.org>
Committed: Thu Feb 18 17:49:48 2016 -0800

----------------------------------------------------------------------
 .../index/config/templateRequestDecorator.js    | 24 +++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/8f17e9ed/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
index 68eb6a1..43655bc 100644
--- a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
+++ b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
@@ -32,6 +32,16 @@ angular.module('index').config(['$provide', function($provide) {
         var $q = $injector.get('$q');
 
         /**
+         * A map of previously-returned promises from past calls to
+         * $templateRequest(). Future calls to $templateRequest() will return
+         * new promises chained to the first promise returned for a given URL,
+         * rather than redo patch processing for every request.
+         *
+         * @type Object.<String, Promise.<String>>
+         */
+        var promiseCache = {};
+
+        /**
          * Array of the raw HTML of all patches which should be applied to the
          * HTML of retrieved templates.
          *
@@ -224,14 +234,24 @@ angular.module('index').config(['$provide', function($provide) {
          * applying all HTML patches from any installed Guacamole extensions
          * to the HTML of the requested template.
          *
+         * @param {String} url
+         *     The URL of the template being requested.
+         *
          * @returns {Promise.<String>}
          *     A Promise which resolves with the patched HTML contents of the
          *     requested template if retrieval of the template is successful.
          */
-        var decoratedTemplateRequest = function decoratedTemplateRequest() {
+        var decoratedTemplateRequest = function decoratedTemplateRequest(url) {
             
             var deferred = $q.defer();
 
+            // Chain to cached promise if it already exists
+            var cachedPromise = promiseCache[url];
+            if (cachedPromise) {
+                cachedPromise.then(deferred.resolve, deferred.reject);
+                return deferred.promise;
+            }
+
             // Resolve promise with patched template HTML
             $delegate.apply(this, arguments).then(function patchTemplate(data) {
 
@@ -281,6 +301,8 @@ angular.module('index').config(['$provide', function($provide) {
 
             }, deferred.reject);
 
+            // Cache this promise for future results
+            promiseCache[url] = deferred.promise;
             return deferred.promise;
 
         };