We have closed
MDL-60402: Calendar slow performance loading contexts with large number of courses
The main reason for slow data loading is not using caching.
We have 3 errors that cause the number of requests to the "context" table to double in proportion to the size of the table.
First error in core_course_category::get_all(). The function gets all the required data in one request, but the "context" data is not used.
The second error is in context_coursecat::instance($record). The record "$record" contains the "context", but does not use it, but requests it from the database, since it is not yet in the cache.
The third error occurs using cache->set_many(). It also gets the context from the database, since it is not in the cache yet.
Possible solution to the problem https://github.com/vel21ripn/moodle/commit/f72aa1fd377b034e029d62cf105674fac7be65f3