From b1d778edbb7f4e7f90863dddd3654937ae04b499 Mon Sep 17 00:00:00 2001 From: Ankita Saxena Date: Sun, 27 Jan 2019 01:48:06 +0530 Subject: [PATCH 1/5] Add loadtime to image obj --- .../dev/head/domain/utilities/ImageFileObjectFactory.js | 7 ++++--- .../head/pages/exploration_player/ImagePreloaderService.js | 7 +++++-- .../templates/dev/head/services/AssetsBackendApiService.js | 4 ++-- .../Image/directives/ImageDirective.js | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js b/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js index fb48d06012b3..860dcbaaa771 100644 --- a/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js +++ b/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js @@ -17,13 +17,14 @@ */ oppia.factory('ImageFileObjectFactory', [function() { - var ImageFile = function(filename, data) { + var ImageFile = function(filename, data, loadTime) { this.filename = filename; this.data = data; + this.loadTime = loadTime; }; - ImageFile.createNew = function(filename, data) { - return new ImageFile(filename, data); + ImageFile.createNew = function(filename, data, loadTime) { + return new ImageFile(filename, data, loadTime); }; return ImageFile; diff --git a/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js b/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js index 36633a58d688..5fb0e4d05788 100644 --- a/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js +++ b/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js @@ -57,8 +57,11 @@ oppia.factory('ImagePreloaderService', [ if (_isInFailedDownload(loadedImageFile.filename)) { _removeFromFailedDownload(loadedImageFile.filename); } - var objectUrl = URL.createObjectURL(loadedImageFile.data); - onLoadCallback(objectUrl); + var obj = { + objectUrl: URL.createObjectURL(loadedImageFile.data), + loadTime: loadedImageFile.loadTime + }; + onLoadCallback(obj); }, function(filename) { onErrorCallback(); }); diff --git a/core/templates/dev/head/services/AssetsBackendApiService.js b/core/templates/dev/head/services/AssetsBackendApiService.js index 25d1d94edaf4..f9c47649f925 100644 --- a/core/templates/dev/head/services/AssetsBackendApiService.js +++ b/core/templates/dev/head/services/AssetsBackendApiService.js @@ -93,7 +93,7 @@ oppia.factory('AssetsBackendApiService', [ AudioFileObjectFactory.createNew(filename, assetBlob)); } else { successCallback( - ImageFileObjectFactory.createNew(filename, assetBlob)); + ImageFileObjectFactory.createNew(filename, assetBlob, Date.now())); } }).error(function() { errorCallback(filename); @@ -223,7 +223,7 @@ oppia.factory('AssetsBackendApiService', [ return $q(function(resolve, reject) { if (_isCached(filename)) { resolve(ImageFileObjectFactory.createNew( - filename, assetsCache[filename])); + filename, assetsCache[filename], Date.now())); } else if (!_isAssetCurrentlyBeingRequested(filename, ASSET_TYPE_IMAGE)) { _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, diff --git a/extensions/rich_text_components/Image/directives/ImageDirective.js b/extensions/rich_text_components/Image/directives/ImageDirective.js index 88826d3caaaa..caf23b3a28e2 100644 --- a/extensions/rich_text_components/Image/directives/ImageDirective.js +++ b/extensions/rich_text_components/Image/directives/ImageDirective.js @@ -60,10 +60,10 @@ oppia.directive('oppiaNoninteractiveImage', [ $scope.isLoadingIndicatorShown = true; $scope.isTryAgainShown = false; ImagePreloaderService.getImageUrl($scope.filepath) - .then(function(objectUrl) { + .then(function(obj) { $scope.isTryAgainShown = false; $scope.isLoadingIndicatorShown = false; - $scope.imageUrl = objectUrl; + $scope.imageUrl = obj.objectUrl; }, function() { $scope.isTryAgainShown = true; $scope.isLoadingIndicatorShown = false; From 5800e5eee9bd7d160f4c03f99400e15871929779 Mon Sep 17 00:00:00 2001 From: Ankita Saxena Date: Tue, 29 Jan 2019 15:34:10 +0530 Subject: [PATCH 2/5] Revert changes --- .../dev/head/domain/utilities/ImageFileObjectFactory.js | 7 +++---- .../head/pages/exploration_player/ImagePreloaderService.js | 7 ++----- .../templates/dev/head/services/AssetsBackendApiService.js | 4 ++-- .../Image/directives/ImageDirective.js | 4 ++-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js b/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js index 860dcbaaa771..fb48d06012b3 100644 --- a/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js +++ b/core/templates/dev/head/domain/utilities/ImageFileObjectFactory.js @@ -17,14 +17,13 @@ */ oppia.factory('ImageFileObjectFactory', [function() { - var ImageFile = function(filename, data, loadTime) { + var ImageFile = function(filename, data) { this.filename = filename; this.data = data; - this.loadTime = loadTime; }; - ImageFile.createNew = function(filename, data, loadTime) { - return new ImageFile(filename, data, loadTime); + ImageFile.createNew = function(filename, data) { + return new ImageFile(filename, data); }; return ImageFile; diff --git a/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js b/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js index 5fb0e4d05788..36633a58d688 100644 --- a/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js +++ b/core/templates/dev/head/pages/exploration_player/ImagePreloaderService.js @@ -57,11 +57,8 @@ oppia.factory('ImagePreloaderService', [ if (_isInFailedDownload(loadedImageFile.filename)) { _removeFromFailedDownload(loadedImageFile.filename); } - var obj = { - objectUrl: URL.createObjectURL(loadedImageFile.data), - loadTime: loadedImageFile.loadTime - }; - onLoadCallback(obj); + var objectUrl = URL.createObjectURL(loadedImageFile.data); + onLoadCallback(objectUrl); }, function(filename) { onErrorCallback(); }); diff --git a/core/templates/dev/head/services/AssetsBackendApiService.js b/core/templates/dev/head/services/AssetsBackendApiService.js index f9c47649f925..25d1d94edaf4 100644 --- a/core/templates/dev/head/services/AssetsBackendApiService.js +++ b/core/templates/dev/head/services/AssetsBackendApiService.js @@ -93,7 +93,7 @@ oppia.factory('AssetsBackendApiService', [ AudioFileObjectFactory.createNew(filename, assetBlob)); } else { successCallback( - ImageFileObjectFactory.createNew(filename, assetBlob, Date.now())); + ImageFileObjectFactory.createNew(filename, assetBlob)); } }).error(function() { errorCallback(filename); @@ -223,7 +223,7 @@ oppia.factory('AssetsBackendApiService', [ return $q(function(resolve, reject) { if (_isCached(filename)) { resolve(ImageFileObjectFactory.createNew( - filename, assetsCache[filename], Date.now())); + filename, assetsCache[filename])); } else if (!_isAssetCurrentlyBeingRequested(filename, ASSET_TYPE_IMAGE)) { _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, diff --git a/extensions/rich_text_components/Image/directives/ImageDirective.js b/extensions/rich_text_components/Image/directives/ImageDirective.js index caf23b3a28e2..88826d3caaaa 100644 --- a/extensions/rich_text_components/Image/directives/ImageDirective.js +++ b/extensions/rich_text_components/Image/directives/ImageDirective.js @@ -60,10 +60,10 @@ oppia.directive('oppiaNoninteractiveImage', [ $scope.isLoadingIndicatorShown = true; $scope.isTryAgainShown = false; ImagePreloaderService.getImageUrl($scope.filepath) - .then(function(obj) { + .then(function(objectUrl) { $scope.isTryAgainShown = false; $scope.isLoadingIndicatorShown = false; - $scope.imageUrl = obj.objectUrl; + $scope.imageUrl = objectUrl; }, function() { $scope.isTryAgainShown = true; $scope.isLoadingIndicatorShown = false; From 4ba96bc62071eabb47127b9b55e0e141535d7032 Mon Sep 17 00:00:00 2001 From: Ankita Saxena Date: Tue, 5 Feb 2019 00:19:03 +0530 Subject: [PATCH 3/5] Add else statement for assets with same filename --- .../dev/head/services/AssetsBackendApiService.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/templates/dev/head/services/AssetsBackendApiService.js b/core/templates/dev/head/services/AssetsBackendApiService.js index 25d1d94edaf4..669cbb277396 100644 --- a/core/templates/dev/head/services/AssetsBackendApiService.js +++ b/core/templates/dev/head/services/AssetsBackendApiService.js @@ -87,7 +87,10 @@ oppia.factory('AssetsBackendApiService', [ throw exception; } } - assetsCache[filename] = assetBlob; + + if (!assetsCache.hasOwnProperty(filename)) { + assetsCache[filename] = assetBlob; + } if (assetType === ASSET_TYPE_AUDIO) { successCallback( AudioFileObjectFactory.createNew(filename, assetBlob)); @@ -216,6 +219,9 @@ oppia.factory('AssetsBackendApiService', [ ASSET_TYPE_AUDIO)) { _fetchFile(explorationId, filename, ASSET_TYPE_AUDIO, resolve, reject); + } else { + _fetchFile(explorationId, filename, ASSET_TYPE_AUDIO, + resolve, reject); } }); }, @@ -228,6 +234,9 @@ oppia.factory('AssetsBackendApiService', [ ASSET_TYPE_IMAGE)) { _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, resolve, reject); + } else { + _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, + resolve, reject); } }); }, From 1dfe77880e1792a5b05f37b4454ece7166d550e5 Mon Sep 17 00:00:00 2001 From: Ankita Saxena Date: Tue, 5 Feb 2019 02:13:31 +0530 Subject: [PATCH 4/5] remove extra else if, update cache always --- .../dev/head/services/AssetsBackendApiService.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/core/templates/dev/head/services/AssetsBackendApiService.js b/core/templates/dev/head/services/AssetsBackendApiService.js index 669cbb277396..2890de8e83cb 100644 --- a/core/templates/dev/head/services/AssetsBackendApiService.js +++ b/core/templates/dev/head/services/AssetsBackendApiService.js @@ -88,9 +88,7 @@ oppia.factory('AssetsBackendApiService', [ } } - if (!assetsCache.hasOwnProperty(filename)) { - assetsCache[filename] = assetBlob; - } + assetsCache[filename] = assetBlob; if (assetType === ASSET_TYPE_AUDIO) { successCallback( AudioFileObjectFactory.createNew(filename, assetBlob)); @@ -215,10 +213,6 @@ oppia.factory('AssetsBackendApiService', [ if (_isCached(filename)) { resolve(AudioFileObjectFactory.createNew( filename, assetsCache[filename])); - } else if (!_isAssetCurrentlyBeingRequested(filename, - ASSET_TYPE_AUDIO)) { - _fetchFile(explorationId, filename, ASSET_TYPE_AUDIO, - resolve, reject); } else { _fetchFile(explorationId, filename, ASSET_TYPE_AUDIO, resolve, reject); @@ -230,10 +224,6 @@ oppia.factory('AssetsBackendApiService', [ if (_isCached(filename)) { resolve(ImageFileObjectFactory.createNew( filename, assetsCache[filename])); - } else if (!_isAssetCurrentlyBeingRequested(filename, - ASSET_TYPE_IMAGE)) { - _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, - resolve, reject); } else { _fetchFile(explorationId, filename, ASSET_TYPE_IMAGE, resolve, reject); From ca1592ff539d7e1352532d170387faf6e87bf9cb Mon Sep 17 00:00:00 2001 From: Ankita Saxena Date: Tue, 5 Feb 2019 02:20:29 +0530 Subject: [PATCH 5/5] Remove extra newline --- core/templates/dev/head/services/AssetsBackendApiService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/core/templates/dev/head/services/AssetsBackendApiService.js b/core/templates/dev/head/services/AssetsBackendApiService.js index 2890de8e83cb..f98110e1a20a 100644 --- a/core/templates/dev/head/services/AssetsBackendApiService.js +++ b/core/templates/dev/head/services/AssetsBackendApiService.js @@ -87,7 +87,6 @@ oppia.factory('AssetsBackendApiService', [ throw exception; } } - assetsCache[filename] = assetBlob; if (assetType === ASSET_TYPE_AUDIO) { successCallback(