forked from EVOgeek/Vmeda.Online
		
	MOBILE-3833 course: Decrease WS calls to get_courses_by_fields
This commit is contained in:
		
							parent
							
								
									147df9b58e
								
							
						
					
					
						commit
						b86cf8d93c
					
				| @ -203,6 +203,15 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|         await this.invalidateCourses(courseIds); |         await this.invalidateCourses(courseIds); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Invalidate list of courses. | ||||||
|  |      * | ||||||
|  |      * @return Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     protected invalidateCourseList(): Promise<void> { | ||||||
|  |         return CoreCourses.invalidateUserCourses(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Helper function to invalidate only selected courses. |      * Helper function to invalidate only selected courses. | ||||||
|      * |      * | ||||||
| @ -213,7 +222,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|         const promises: Promise<void>[] = []; |         const promises: Promise<void>[] = []; | ||||||
| 
 | 
 | ||||||
|         // Invalidate course completion data.
 |         // Invalidate course completion data.
 | ||||||
|         promises.push(CoreCourses.invalidateUserCourses().finally(() => |         promises.push(this.invalidateCourseList().finally(() => | ||||||
|             CoreUtils.allPromises(courseIds.map((courseId) => |             CoreUtils.allPromises(courseIds.map((courseId) => | ||||||
|                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); |                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); | ||||||
| 
 | 
 | ||||||
| @ -397,7 +406,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|                 course.hidden = !!data.value; |                 course.hidden = !!data.value; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             await this.invalidateCourses([course.id]); |             await this.invalidateCourseList(); | ||||||
|             await this.filterCourses(); |             await this.filterCourses(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -409,7 +418,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
| 
 | 
 | ||||||
|             course.lastaccess = CoreTimeUtils.timestamp(); |             course.lastaccess = CoreTimeUtils.timestamp(); | ||||||
| 
 | 
 | ||||||
|             await this.invalidateCourses([course.id]); |             await this.invalidateCourseList(); | ||||||
|             await this.filterCourses(); |             await this.filterCourses(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -85,6 +85,17 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom | |||||||
|         await this.invalidateCourses(courseIds); |         await this.invalidateCourses(courseIds); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Invalidate list of courses. | ||||||
|  |      * | ||||||
|  |      * @return Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     protected async invalidateCourseList(): Promise<void> { | ||||||
|  |         return this.site.isVersionGreaterEqualThan('3.8') | ||||||
|  |             ? CoreCourses.invalidateRecentCourses() | ||||||
|  |             : CoreCourses.invalidateUserCourses(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Helper function to invalidate only selected courses. |      * Helper function to invalidate only selected courses. | ||||||
|      * |      * | ||||||
| @ -94,12 +105,8 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom | |||||||
|     protected async invalidateCourses(courseIds: number[]): Promise<void> { |     protected async invalidateCourses(courseIds: number[]): Promise<void> { | ||||||
|         const promises: Promise<void>[] = []; |         const promises: Promise<void>[] = []; | ||||||
| 
 | 
 | ||||||
|         const invalidateCoursePromise = this.site.isVersionGreaterEqualThan('3.8') |  | ||||||
|             ? CoreCourses.invalidateRecentCourses() |  | ||||||
|             : CoreCourses.invalidateUserCourses(); |  | ||||||
| 
 |  | ||||||
|         // Invalidate course completion data.
 |         // Invalidate course completion data.
 | ||||||
|         promises.push(invalidateCoursePromise.finally(() => |         promises.push(this.invalidateCourseList().finally(() => | ||||||
|             CoreUtils.allPromises(courseIds.map((courseId) => |             CoreUtils.allPromises(courseIds.map((courseId) => | ||||||
|                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); |                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); | ||||||
| 
 | 
 | ||||||
| @ -179,13 +186,13 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom | |||||||
|             this.courses.splice(courseIndex, 1); |             this.courses.splice(courseIndex, 1); | ||||||
|             this.courses.unshift(course); |             this.courses.unshift(course); | ||||||
| 
 | 
 | ||||||
|             await this.invalidateCourses([course.id]); |             await this.invalidateCourseList(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED && |         if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED && | ||||||
|             data.state == CoreCoursesProvider.STATE_FAVOURITE && course) { |             data.state == CoreCoursesProvider.STATE_FAVOURITE && course) { | ||||||
|             course.isfavourite = !!data.value; |             course.isfavourite = !!data.value; | ||||||
|             await this.invalidateCourses([course.id]); |             await this.invalidateCourseList(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -81,6 +81,15 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im | |||||||
|         await this.invalidateCourses(courseIds); |         await this.invalidateCourses(courseIds); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Invalidate list of courses. | ||||||
|  |      * | ||||||
|  |      * @return Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     protected async invalidateCourseList(): Promise<void> { | ||||||
|  |         return AddonBlockStarredCourses.invalidateStarredCourses(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Helper function to invalidate only selected courses. |      * Helper function to invalidate only selected courses. | ||||||
|      * |      * | ||||||
| @ -91,7 +100,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im | |||||||
|         const promises: Promise<void>[] = []; |         const promises: Promise<void>[] = []; | ||||||
| 
 | 
 | ||||||
|         // Invalidate course completion data.
 |         // Invalidate course completion data.
 | ||||||
|         promises.push(AddonBlockStarredCourses.invalidateStarredCourses().finally(() => |         promises.push(this.invalidateCourseList().finally(() => | ||||||
|             CoreUtils.allPromises(courseIds.map((courseId) => |             CoreUtils.allPromises(courseIds.map((courseId) => | ||||||
|                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); |                 AddonCourseCompletion.invalidateCourseCompletion(courseId))))); | ||||||
| 
 | 
 | ||||||
| @ -172,7 +181,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im | |||||||
|                 this.courses.unshift(course); |                 this.courses.unshift(course); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             await this.invalidateCourses([course.id]); |             await this.invalidateCourseList(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user