From 3fccc3c3cdcd02cd18450ad3ffd4408c4a8450e1 Mon Sep 17 00:00:00 2001 From: Carlos Mantilla Date: Tue, 17 Feb 2015 10:33:36 +0200 Subject: [PATCH 1/2] WIP: Removing repeat request in the dashboard. --- .../client/app/scripts/services/events.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/templates/client/app/scripts/services/events.js b/app/templates/client/app/scripts/services/events.js index 68fe2a4..7cc1b55 100644 --- a/app/templates/client/app/scripts/services/events.js +++ b/app/templates/client/app/scripts/services/events.js @@ -16,6 +16,9 @@ angular.module('clientApp') // Update event broadcast name. var broadcastUpdateEventName = 'SkeletonEventsChange'; + // Cache promises. + var getData = {}; + /** * Return the promise with the events list, from cache or the server. @@ -27,11 +30,16 @@ angular.module('clientApp') */ this.get = function(companyId, userId) { var cacheId = companyId + ':' + userId; - if (cache && cache[cacheId]) { - return $q.when(cache[cacheId].data); + + // Get cache promise or data. + if (getData[cacheId] || cache[cacheId]) { + getData[cacheId] = $q.when(getData[cacheId] || cache[cacheId].data); } - return getDataFromBackend(companyId, userId); + // Otherwiose get data from the server. + getData[cacheId] = (getData[cacheId] || getDataFromBackend(companyId, userId)); + + return getData[cacheId]; }; /** From 281ebf38a24e3dc1e07692a1e0482c09a4fd3495 Mon Sep 17 00:00:00 2001 From: Carlos Mantilla Date: Thu, 19 Feb 2015 09:38:11 +0200 Subject: [PATCH 2/2] docs: correct typo. --- app/templates/client/app/scripts/services/events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/client/app/scripts/services/events.js b/app/templates/client/app/scripts/services/events.js index 7cc1b55..b555ef8 100644 --- a/app/templates/client/app/scripts/services/events.js +++ b/app/templates/client/app/scripts/services/events.js @@ -36,7 +36,7 @@ angular.module('clientApp') getData[cacheId] = $q.when(getData[cacheId] || cache[cacheId].data); } - // Otherwiose get data from the server. + // Otherwise get data from the server. getData[cacheId] = (getData[cacheId] || getDataFromBackend(companyId, userId)); return getData[cacheId];