From d2b9cf89d87de59f2356dc51675e3533dbcea615 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 22 Mar 2022 15:48:49 +0100 Subject: [PATCH] MOBILE-3833 module: Improve performance of getModuleStoredSize --- .../services/module-prefetch-delegate.ts | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/core/features/course/services/module-prefetch-delegate.ts b/src/core/features/course/services/module-prefetch-delegate.ts index d75e36759..1556a75da 100644 --- a/src/core/features/course/services/module-prefetch-delegate.ts +++ b/src/core/features/course/services/module-prefetch-delegate.ts @@ -482,23 +482,17 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { - let downloadedSize = await this.getModuleDownloadedSize(module, courseId); - - if (isNaN(downloadedSize)) { - downloadedSize = 0; - } - const site = CoreSites.getCurrentSite(); const handler = this.getPrefetchHandlerFor(module.modname); - if (!handler || !site) { - // If there is no handler then we can't find out the component name. - // We can't work out the cached size, so just return downloaded size. - return downloadedSize; - } - const cachedSize = await site.getComponentCacheSize(handler.component, module.id); + const [downloadedSize, cachedSize] = await Promise.all([ + this.getModuleDownloadedSize(module, courseId), + handler && site ? site.getComponentCacheSize(handler.component, module.id) : 0, + ]); - return cachedSize + downloadedSize; + const totalSize = cachedSize + downloadedSize; + + return isNaN(totalSize) ? 0 : totalSize; } /**