Merge pull request #2025 from dpalou/MOBILE-3064

MOBILE-3064 course: Don't call check_updates after prefetch
main
Juan Leyva 2019-07-31 13:04:22 +02:00 committed by GitHub
commit 0139910fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 23 deletions

View File

@ -149,7 +149,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
this.prefetchHandler.getDownloadSize(this.module, this.courseId, true).then((size) => { this.prefetchHandler.getDownloadSize(this.module, this.courseId, true).then((size) => {
return this.courseHelper.prefetchModule(this.prefetchHandler, this.module, size, this.courseId, refresh); return this.courseHelper.prefetchModule(this.prefetchHandler, this.module, size, this.courseId, refresh);
}).then(() => { }).then(() => {
this.courseHelper.calculateSectionStatus(this.section, this.courseId); this.courseHelper.calculateSectionStatus(this.section, this.courseId, false, false);
}).catch((error) => { }).catch((error) => {
// Error, hide spinner. // Error, hide spinner.
this.spinner = false; this.spinner = false;

View File

@ -442,15 +442,7 @@ export class CoreCourseSectionPage implements OnDestroy {
*/ */
prefetchCourse(): void { prefetchCourse(): void {
this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course, this.sections, this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course, this.sections,
this.courseHandlers, this.courseMenuHandlers) this.courseHandlers, this.courseMenuHandlers).catch((error) => {
.then(() => {
if (this.downloadEnabled) {
// Recalculate the status.
this.courseHelper.calculateSectionsStatus(this.sections, this.course.id).catch(() => {
// Ignore errors (shouldn't happen).
});
}
}).catch((error) => {
if (!this.isDestroyed) { if (!this.isDestroyed) {
this.domUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); this.domUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true);
} }

View File

@ -187,16 +187,19 @@ export class CoreCourseHelperProvider {
* @param {any} section Section to calculate its status. It can't be "All sections". * @param {any} section Section to calculate its status. It can't be "All sections".
* @param {number} courseId Course ID the section belongs to. * @param {number} courseId Course ID the section belongs to.
* @param {boolean} [refresh] True if it shouldn't use module status cache (slower). * @param {boolean} [refresh] True if it shouldn't use module status cache (slower).
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
* @return {Promise<any>} Promise resolved when the status is calculated. * @return {Promise<any>} Promise resolved when the status is calculated.
*/ */
calculateSectionStatus(section: any, courseId: number, refresh?: boolean): Promise<any> { calculateSectionStatus(section: any, courseId: number, refresh?: boolean, checkUpdates: boolean = true): Promise<any> {
if (section.id == CoreCourseProvider.ALL_SECTIONS_ID) { if (section.id == CoreCourseProvider.ALL_SECTIONS_ID) {
return Promise.reject(null); return Promise.reject(null);
} }
// Get the status of this section. // Get the status of this section.
return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id, refresh, true).then((result) => { return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id, refresh, true, checkUpdates)
.then((result) => {
// Check if it's being downloaded. // Check if it's being downloaded.
const downloadId = this.getSectionDownloadId(section); const downloadId = this.getSectionDownloadId(section);
if (this.prefetchDelegate.isBeingDownloaded(downloadId)) { if (this.prefetchDelegate.isBeingDownloaded(downloadId)) {
@ -228,9 +231,10 @@ export class CoreCourseHelperProvider {
* @param {any[]} sections Sections to calculate their status. * @param {any[]} sections Sections to calculate their status.
* @param {number} courseId Course ID the sections belong to. * @param {number} courseId Course ID the sections belong to.
* @param {boolean} [refresh] True if it shouldn't use module status cache (slower). * @param {boolean} [refresh] True if it shouldn't use module status cache (slower).
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
* @return {Promise<void>} Promise resolved when the states are calculated. * @return {Promise<void>} Promise resolved when the states are calculated.
*/ */
calculateSectionsStatus(sections: any[], courseId: number, refresh?: boolean): Promise<void> { calculateSectionsStatus(sections: any[], courseId: number, refresh?: boolean, checkUpdates: boolean = true): Promise<void> {
const promises = []; const promises = [];
let allSectionsSection, let allSectionsSection,
allSectionsStatus; allSectionsStatus;
@ -242,7 +246,7 @@ export class CoreCourseHelperProvider {
section.isCalculating = true; section.isCalculating = true;
} else { } else {
section.isCalculating = true; section.isCalculating = true;
promises.push(this.calculateSectionStatus(section, courseId, refresh).then((result) => { promises.push(this.calculateSectionStatus(section, courseId, refresh, checkUpdates).then((result) => {
// Calculate "All sections" status. // Calculate "All sections" status.
allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status); allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status);
}).finally(() => { }).finally(() => {
@ -1331,7 +1335,7 @@ export class CoreCourseHelperProvider {
// Download only this section. // Download only this section.
return this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => { return this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => {
// Calculate the status of the section that finished. // Calculate the status of the section that finished.
return this.calculateSectionStatus(section, courseId); return this.calculateSectionStatus(section, courseId, false, false);
}); });
} else { } else {
// Download all the sections except "All sections". // Download all the sections except "All sections".
@ -1343,7 +1347,7 @@ export class CoreCourseHelperProvider {
if (section.id != CoreCourseProvider.ALL_SECTIONS_ID) { if (section.id != CoreCourseProvider.ALL_SECTIONS_ID) {
promises.push(this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => { promises.push(this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => {
// Calculate the status of the section that finished. // Calculate the status of the section that finished.
return this.calculateSectionStatus(section, courseId).then((result) => { return this.calculateSectionStatus(section, courseId, false, false).then((result) => {
// Calculate "All sections" status. // Calculate "All sections" status.
allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status); allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status);
}); });

View File

@ -795,6 +795,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
* @param {number} [sectionId] ID of the section the modules belong to. * @param {number} [sectionId] ID of the section the modules belong to.
* @param {boolean} [refresh] True if it should always check the DB (slower). * @param {boolean} [refresh] True if it should always check the DB (slower).
* @param {boolean} [onlyToDisplay] True if the status will only be used to determine which button should be displayed. * @param {boolean} [onlyToDisplay] True if the status will only be used to determine which button should be displayed.
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
* @return {Promise<any>} Promise resolved with an object with the following properties: * @return {Promise<any>} Promise resolved with an object with the following properties:
* - status (string) Status of the module. * - status (string) Status of the module.
* - total (number) Number of modules. * - total (number) Number of modules.
@ -803,12 +804,15 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
* - CoreConstants.DOWNLOADING (any[]) Modules with state DOWNLOADING. * - CoreConstants.DOWNLOADING (any[]) Modules with state DOWNLOADING.
* - CoreConstants.OUTDATED (any[]) Modules with state OUTDATED. * - CoreConstants.OUTDATED (any[]) Modules with state OUTDATED.
*/ */
getModulesStatus(modules: any[], courseId: number, sectionId?: number, refresh?: boolean, onlyToDisplay?: boolean): any { getModulesStatus(modules: any[], courseId: number, sectionId?: number, refresh?: boolean, onlyToDisplay?: boolean,
checkUpdates: boolean = true): any {
const promises = [], const promises = [],
result: any = { result: any = {
total: 0 total: 0
}; };
let status = CoreConstants.NOT_DOWNLOADABLE; let status = CoreConstants.NOT_DOWNLOADABLE,
promise;
// Init result. // Init result.
result[CoreConstants.NOT_DOWNLOADED] = []; result[CoreConstants.NOT_DOWNLOADED] = [];
@ -816,11 +820,17 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
result[CoreConstants.DOWNLOADING] = []; result[CoreConstants.DOWNLOADING] = [];
result[CoreConstants.OUTDATED] = []; result[CoreConstants.OUTDATED] = [];
if (checkUpdates) {
// Check updates in course. Don't use getCourseUpdates because the list of modules might not be the whole course list. // Check updates in course. Don't use getCourseUpdates because the list of modules might not be the whole course list.
return this.getCourseUpdatesByCourseId(courseId).catch(() => { promise = this.getCourseUpdatesByCourseId(courseId).catch(() => {
// Cannot get updates. // Cannot get updates.
return false; return false;
}).then((updates) => { });
} else {
promise = Promise.resolve(false);
}
return promise.then((updates) => {
modules.forEach((module) => { modules.forEach((module) => {
// Check if the module has a prefetch handler. // Check if the module has a prefetch handler.