When called with a list of course IDs, this change makes it preload
the contexts and categories before further processing. This saves a
number of queries, depending on how many courses you call it for.
(Typically the function is called with a list of all your enrolled
courses.)
The change may also improve performance for other web services that
call the validate_courses function.