Skip to content

Commit 4165506

Browse files
committed
MOBILE-3890 course: Add cache for modules
1 parent dcc76fd commit 4165506

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/core/features/course/services/course.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ export class CoreCourseProvider {
140140
protected lastNavigationCheck: {
141141
courseId: number;
142142
courseLang: string | undefined;
143+
cmId: number;
144+
cmLang: string | undefined;
143145
timestamp: number;
144146
}= {
145147
courseId: 0,
146148
courseLang: undefined,
149+
cmId: 0,
150+
cmLang: undefined,
147151
timestamp: 0,
148152
};
149153

@@ -201,16 +205,27 @@ export class CoreCourseProvider {
201205
protected async getCourseLanguageFromRoute(): Promise<string | undefined> {
202206
let course = CoreNavigator.getRouteParam<CoreCourseSearchedData>('course');
203207
const courseId = course?.id ?? CoreNavigator.getRouteNumberParam('courseId');
208+
204209
if (!courseId) {
205210
// Not in a course/module, empty the cache and return.
206211
this.lastNavigationCheck.courseId = 0;
207212
this.lastNavigationCheck.courseLang = undefined;
213+
this.lastNavigationCheck.cmId = 0;
214+
this.lastNavigationCheck.cmLang = undefined;
208215

209216
return;
210217
}
211218

212219
const cmId = CoreNavigator.getRouteNumberParam('cmId');
213220
if (cmId) {
221+
if (this.lastNavigationCheck.cmId === cmId) {
222+
console.error('Using cached cm language', this.lastNavigationCheck.cmLang);
223+
224+
return this.lastNavigationCheck.cmLang;
225+
}
226+
this.lastNavigationCheck.cmId = cmId;
227+
this.lastNavigationCheck.cmLang = undefined;
228+
214229
// TODO: In the future this should directly return the module language instead of checking the delegate.
215230
const module = await CorePromiseUtils.ignoreErrors(
216231
CoreCourse.getModule(cmId, courseId, undefined, true),
@@ -221,12 +236,19 @@ export class CoreCourseProvider {
221236
CoreCourseModuleDelegate.getModuleForcedLang(module),
222237
);
223238
if (lang) {
239+
this.lastNavigationCheck.cmLang = lang;
240+
224241
return lang;
225242
}
226243
}
244+
} else {
245+
this.lastNavigationCheck.cmId = 0;
246+
this.lastNavigationCheck.cmLang = undefined;
227247
}
228248

229249
if (this.lastNavigationCheck.courseId === courseId) {
250+
console.error('Using cached course language', this.lastNavigationCheck.courseLang);
251+
230252
return this.lastNavigationCheck.courseLang;
231253
}
232254
this.lastNavigationCheck.courseId = courseId;

0 commit comments

Comments
 (0)