/course/scales.php will be very slow with lots of courses and course modules (MDL-1883 and MDL-9939). Basically this is because the number of times that a specific scale is used is calculated by asking each module instance "are you using this scale" and then doing $results++ if it is.
A solution that is multiple orders of magnitude faster is to use count_records() for each module type. This way the modular approach is still there. One big SQL can't be used as modules have different ways of storing the used scales.
One way to fix this is to loop every installed module type in site_scale_used() and then ask for the count of the given scale for that module. But which would be less disruptive: add a new function like [modulename]_scale_count()or to add a parameter $count to the current [modulename]_scale_used()?
Either way, all modules should be changed in order to get this to be consistent. Or, function_exists() has to juggle between the faster way to count or the old way.
In my opinion the nicest way would be to have just the [modulename]_scale_count() and then use that too to decide whether the scale is used at all, and then deprecate the [modulename]_scale_used() function and for a while let it do "return [modulename_scale_used() > 0;", then after a grace period, remove the function.
Scratch that, just realised that all of this has been refactored in the second coming of the gradebook. I'll do a quick'n'dirty (is there any other kind?)fix for 1.8 series and post a patch (tomorrow)in MDL-1883, in case others need to speed up scales for 1.8 too.
Awesome, Samuli, thanks!
For those that have the "scales too slow on 1.8" issue: I attached a patch for 1.8 series in MDL-1883. It's pretty much the same what Petr did for 1.9. I'll check it in 1.8 stable, if there are no objections, and I get around to test it a bit on a large site next week...
(Edited by Martin Dougiamas to fix bug number - original submission Friday, 21 September 2007, 02:38 PM)