project: Moodle
summary: Develop course structure caching
description: The main goal of this change is to move the content of the fields course.modinfo and course.sectioncache to MUC. More complete list of changes: - classes course_modinfo, cm_info, section_cache no longer extend stdClass and all properties are read-only. No more deprecated but still used everywhere public properties - all properties have getters and you can legally use either $modinfo->cms or $modinfo->get_cms() - classes cm_info and section_cache no longer calculate any data on initialisation and only calculate it when it is needed (saves extra DB queries when conditional availability is enabled). - database fields course.modinfo and course.sectioncache are removed, new application cache core/coursemodinfo stores this information. - course cache now additionally stores some fields from course table such as format, enableavailability, groupmode, etc. that are necessary when calculating availability or additional section fields - new field course.cacherev added to table course and it is incremented every time the course cache is reset. Object in cache stores the value of cacherev at the moment when cache was built. This allows to avoid race conditions when course cache was simultaneously reset and rebuild by different people and became corrupt. Main changes for users - less db queries, less RAM usage on heavy pages such as "My courses" - much less probability of corrupt course cache (hopefully none at all) - "Purge all caches" purges course caches as well - Every core upgrade purges course caches Notes for developers - Do not access removed fields course.modinfo and course.sectioncache - If you need the raw user-independed information - call get_fast_modinfo($courseorid, -1) - Do not try to overwrite/append properties of course_modinfo or cm_info - do not hint any of those classes as stdClass in function arguments or youll hit fatal error - Enjoy IDE hints for the properties and methods in modinfo classes - When calling get_fast_modinfo() for the list of courses make sure to retrieve/pass field cacherev. Otherwise an extra db query will be made. Not necessary when calling get_fast_modinfo() for current course. Most of core API functions returning list of courses will return you this field anyway.

1.summary: moveto_module() should not modify arguments
description: At the moment function moveto_module($mod, $section, $beforemod=NULL) may modify the value of $mod->visible . It is only needed for /course/reset.php to serve AJAX requests to move the module. First argument may be an instance of cm_info. In Im making all properties of cm_info read-only and this function is the only problem. Instead moveto_module may return the new value for module visibility. Also to mention that modifying JUST $mod->visible is not correct anyway. Other properties such as $mod->uservisible may be affected by this change as well.
2.summary: Performance and usability improvements in class cm_info
description: Classes cm_info should not perform any calculations/requests in constructor, all properties should be read-only and those that need calculations have getters methods so they are calculated on the first request only. What it saves: when we call get_fast_modinfo() for the whole course but only actually need one activity (or only activities in one sections, activities of particular type, etc.), the other activities visibility is not calculated. At the moment it can be expensive if conditions or groups are used.
3.summary: Performance and usability improvements in class section_info
description: - Calculate uservisible, available, availabe_info on demand only - Proper phpdocs for properties and methods - Do not store unnecessary data
4.summary: Usability improvements in class course_modinfo
description: Make properties read-only with getter methods, add phpdocs

Below is an instruction that describes a task, paired with an input that provides an epic with this format: 
"project": "Name of the project" 
"summary": "Summary of the epic user story" 
"description": "Description of the epic user story". Write a response that appropriately completes the request.### Instruction:
Break this epic user story into smaller tasks to help the developers understand the epic better, you can divide this epic into as much as you want depending on the complexity of the epic.
### Input:
project: Moodle
summary: Develop course structure caching
description: The main goal of this change is to move the content of the fields course.modinfo and course.sectioncache to MUC. More complete list of changes: - classes course_modinfo, cm_info, section_cache no longer extend stdClass and all properties are read-only. No more deprecated but still used everywhere public properties - all properties have getters and you can legally use either $modinfo->cms or $modinfo->get_cms() - classes cm_info and section_cache no longer calculate any data on initialisation and only calculate it when it is needed (saves extra DB queries when conditional availability is enabled). - database fields course.modinfo and course.sectioncache are removed, new application cache core/coursemodinfo stores this information. - course cache now additionally stores some fields from course table such as format, enableavailability, groupmode, etc. that are necessary when calculating availability or additional section fields - new field course.cacherev added to table course and it is incremented every time the course cache is reset. Object in cache stores the value of cacherev at the moment when cache was built. This allows to avoid race conditions when course cache was simultaneously reset and rebuild by different people and became corrupt. Main changes for users - less db queries, less RAM usage on heavy pages such as "My courses" - much less probability of corrupt course cache (hopefully none at all) - "Purge all caches" purges course caches as well - Every core upgrade purges course caches Notes for developers - Do not access removed fields course.modinfo and course.sectioncache - If you need the raw user-independed information - call get_fast_modinfo($courseorid, -1) - Do not try to overwrite/append properties of course_modinfo or cm_info - do not hint any of those classes as stdClass in function arguments or youll hit fatal error - Enjoy IDE hints for the properties and methods in modinfo classes - When calling get_fast_modinfo() for the list of courses make sure to retrieve/pass field cacherev. Otherwise an extra db query will be made. Not necessary when calling get_fast_modinfo() for current course. Most of core API functions returning list of courses will return you this field anyway.

### Response:
1.summary: moveto_module() should not modify arguments
description: At the moment function moveto_module($mod, $section, $beforemod=NULL) may modify the value of $mod->visible . It is only needed for /course/reset.php to serve AJAX requests to move the module. First argument may be an instance of cm_info. In Im making all properties of cm_info read-only and this function is the only problem. Instead moveto_module may return the new value for module visibility. Also to mention that modifying JUST $mod->visible is not correct anyway. Other properties such as $mod->uservisible may be affected by this change as well.
2.summary: Performance and usability improvements in class cm_info
description: Classes cm_info should not perform any calculations/requests in constructor, all properties should be read-only and those that need calculations have getters methods so they are calculated on the first request only. What it saves: when we call get_fast_modinfo() for the whole course but only actually need one activity (or only activities in one sections, activities of particular type, etc.), the other activities visibility is not calculated. At the moment it can be expensive if conditions or groups are used.
3.summary: Performance and usability improvements in class section_info
description: - Calculate uservisible, available, availabe_info on demand only - Proper phpdocs for properties and methods - Do not store unnecessary data
4.summary: Usability improvements in class course_modinfo
description: Make properties read-only with getter methods, add phpdocs
