MOBILE-3833 course: Improve getCoursesAdminAndNavOptions performance

main
Dani Palou 2022-03-23 15:02:24 +01:00
parent 05ffa6f807
commit 147df9b58e
1 changed files with 6 additions and 17 deletions

View File

@ -20,6 +20,7 @@ import { CoreStatusWithWarningsWSResponse, CoreWarningsWSResponse, CoreWSExterna
import { CoreEvents } from '@singletons/events';
import { CoreWSError } from '@classes/errors/wserror';
import { CoreCourseAnyCourseDataWithExtraInfoAndOptions, CoreCourseWithImageAndColor } from './courses-helper';
import { CoreUtils } from '@services/utils/utils';
const ROOT_CACHE_KEY = 'mmCourses:';
@ -625,25 +626,13 @@ export class CoreCoursesProvider {
// Get the list of courseIds to use based on the param.
courseIds = await this.getCourseIdsForAdminAndNavOptions(courseIds, siteId);
let navOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
let admOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
// Get user navigation and administration options.
try {
navOptions = await this.getUserNavigationOptions(courseIds, siteId);
} catch {
// Couldn't get it, return empty options.
navOptions = {};
}
const [navOptions, admOptions] = await Promise.all([
CoreUtils.ignoreErrors(this.getUserNavigationOptions(courseIds, siteId), {}),
CoreUtils.ignoreErrors(this.getUserAdministrationOptions(courseIds, siteId), {}),
]);
try {
admOptions = await this.getUserAdministrationOptions(courseIds, siteId);
} catch {
// Couldn't get it, return empty options.
admOptions = {};
}
return ({ navOptions: navOptions, admOptions: admOptions });
return { navOptions: navOptions, admOptions: admOptions };
}
/**