@@ -38,10 +38,12 @@ export class CoreFilterHelperProvider {
3838 protected moduleContextsCache : {
3939 [ siteId : string ] : {
4040 [ courseId : number ] : {
41- contexts : CoreFilterClassifiedFilters ,
42- time : number
43- }
44- }
41+ [ contextLevel : string ] : {
42+ contexts : CoreFilterClassifiedFilters ,
43+ time : number ,
44+ } ,
45+ } ,
46+ } ,
4547 } = { } ;
4648
4749 constructor ( logger : CoreLoggerProvider ,
@@ -110,7 +112,7 @@ export class CoreFilterHelperProvider {
110112 return getFilters ( ) . then ( ( contexts ) => {
111113
112114 return this . filterProvider . getAvailableInContexts ( contexts , siteId ) . then ( ( filters ) => {
113- this . storeInMemoryCache ( options . courseId , filters , siteId ) ;
115+ this . storeInMemoryCache ( options . courseId , contextLevel , filters , siteId ) ;
114116
115117 return filters [ contextLevel ] [ instanceId ] || [ ] ;
116118 } ) ;
@@ -278,14 +280,16 @@ export class CoreFilterHelperProvider {
278280 const siteId = site . getId ( ) ;
279281
280282 // Check if we have the context in the memory cache.
281- if ( this . moduleContextsCache [ siteId ] && this . moduleContextsCache [ siteId ] [ courseId ] ) {
282- const cachedCourse = this . moduleContextsCache [ siteId ] [ courseId ] ;
283+ if ( this . moduleContextsCache [ siteId ] && this . moduleContextsCache [ siteId ] [ courseId ] &&
284+ this . moduleContextsCache [ siteId ] [ courseId ] [ contextLevel ] ) {
285+
286+ const cachedData = this . moduleContextsCache [ siteId ] [ courseId ] [ contextLevel ] ;
283287
284288 if ( ! this . appProvider . isOnline ( ) ||
285- Date . now ( ) <= cachedCourse . time + site . getExpirationDelay ( CoreSite . FREQUENCY_RARELY ) ) {
289+ Date . now ( ) <= cachedData . time + site . getExpirationDelay ( CoreSite . FREQUENCY_RARELY ) ) {
286290
287291 // We can use cache, return the filters if found.
288- return cachedCourse . contexts [ contextLevel ] && cachedCourse . contexts [ contextLevel ] [ instanceId ] ;
292+ return cachedData . contexts [ contextLevel ] && cachedData . contexts [ contextLevel ] [ instanceId ] ;
289293 }
290294 }
291295 }
@@ -316,11 +320,14 @@ export class CoreFilterHelperProvider {
316320 * @param contexts Filters to store, classified by contextlevel and instanceid
317321 * @param siteId Site ID.
318322 */
319- protected storeInMemoryCache ( courseId : number , contexts : CoreFilterClassifiedFilters , siteId : string ) : void {
323+ protected storeInMemoryCache ( courseId : number , contextLevel : string , contexts : CoreFilterClassifiedFilters , siteId : string )
324+ : void {
325+
320326 this . moduleContextsCache [ siteId ] = this . moduleContextsCache [ siteId ] || { } ;
321- this . moduleContextsCache [ siteId ] [ courseId ] = {
327+ this . moduleContextsCache [ siteId ] [ courseId ] = this . moduleContextsCache [ siteId ] [ courseId ] || { } ;
328+ this . moduleContextsCache [ siteId ] [ courseId ] [ contextLevel ] = {
322329 contexts : contexts ,
323- time : Date . now ( )
330+ time : Date . now ( ) ,
324331 } ;
325332 }
326333}
0 commit comments