]> git.mjollnir.org Git - moodle.git/commit
accesslib: get_my_courses() rework, new get_courses_bycap_fromsess()
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:03:49 +0000 (07:03 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:03:49 +0000 (07:03 +0000)
commite1d5e5c1810480a9eeb8ba33e28bc5124791951f
treee3643c61871b24605f56d1e6432213683ba55604
parent13a794757e0824acafd0f686efbd268c61b2a5ce
accesslib: get_my_courses() rework, new get_courses_bycap_fromsess()

get_my_courses() goes from a bazillion queries (500 in some sample
cases) to 1 for the logged-in user, and 4 for a non-logged-in user.

One of those queries brings a *lot* of data across (all rows from
mdl_course) so there is room for serious optimisation.

  However, this clocks at ~300 ms on my laptop, costly, but not
  the end of the world. If your PHP-DB link has bandwidth probs
  it might be a problem.

A few important changes to get_my_courses()

 - (Compat ALERT!) the default fields are less than before --
   (will be followed by patches that fix the callers!) our defaults
   had grown to quite a bit because of the crazy caching scheme it had

 - the $fields parameter is to name _additional_ fields you need, and
   ideally wants them passed as an array. Will cope with old-style
   strings too.

 - the returned courses have an extra property "context" that is
   a fully valid context object, so if the caller needs to perform
   further accesslib checks, we save a query per course down the road

The work is done in the newfangled get_courses_bycap_fromsess()
which is brute-force but fast. I'm sure we can optimise the common
cases a lot in it if we try. It'd be worthwhile to

  - reduce the rows we grab - that's really boneheaded

  - if we copy and tweak the logic of has_cap_fromsess() in it
    it can be made even faster
lib/accesslib.php
lib/datalib.php