@@ -30,7 +30,8 @@ angular.module('mm.addons.mod_quiz')
3030
3131 var self = { } ,
3232 blockedQuizzes = { } ,
33- $mmaModQuizSync ; // We'll inject it using $injector to prevent circular dependencies.
33+ $mmaModQuizSync , // We'll inject it using $injector to prevent circular dependencies.
34+ downloadPromises = { } ; // Store download promises to prevent duplicate requests.
3435
3536 // Constants.
3637
@@ -2074,10 +2075,19 @@ angular.module('mm.addons.mod_quiz')
20742075 quiz ,
20752076 quizAccessInfo ,
20762077 preflightData = { } ,
2077- scope ;
2078+ scope ,
2079+ prefetchPromise ,
2080+ deleted = false ;
2081+
2082+ if ( downloadPromises [ siteId ] && downloadPromises [ siteId ] [ module . id ] ) {
2083+ // There's already a download ongoing for this package, return the promise.
2084+ return downloadPromises [ siteId ] [ module . id ] ;
2085+ } else if ( ! downloadPromises [ siteId ] ) {
2086+ downloadPromises [ siteId ] = { } ;
2087+ }
20782088
20792089 // Mark package as downloading.
2080- return $mmFilepool . storePackageStatus ( siteId , mmaModQuizComponent , module . id , mmCoreDownloading ) . then ( function ( ) {
2090+ prefetchPromise = $mmFilepool . storePackageStatus ( siteId , mmaModQuizComponent , module . id , mmCoreDownloading ) . then ( function ( ) {
20812091 // Get quiz.
20822092 return self . getQuiz ( courseId , module . id , siteId ) . then ( function ( q ) {
20832093 quiz = q ;
@@ -2161,7 +2171,14 @@ angular.module('mm.addons.mod_quiz')
21612171 if ( scope ) {
21622172 scope . $destroy ( ) ;
21632173 }
2174+ deleted = true ;
2175+ delete downloadPromises [ siteId ] [ module . id ] ;
21642176 } ) ;
2177+
2178+ if ( ! deleted ) {
2179+ downloadPromises [ siteId ] [ module . id ] = prefetchPromise ;
2180+ }
2181+ return prefetchPromise ;
21652182 } ;
21662183
21672184 /**
0 commit comments