Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-7196

Caching get_record calls can give performance improvement

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7, 1.8
    • Fix Version/s: 1.7, 1.8
    • Labels:
      None
    • Environment:
      Tested using Moodle HEAD.
    • Affected Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE

      Description

      It is possible to reduce the number of database queries used for a stock Moodle course home page from 87 to 67 (a 23% reduction) by caching the result of get_record.

      (These stats were obtained from the performance info in the footer of standard theme, with debug turned off. Numbers are higher with debug on.)

      The attached patch caches get_record results (only when $CFG->cachegetrecord is true, when you're requesting *, and when the only condition is id=something) as a static variable and uncaches results as appropriate when update_record or set_field are called. It applies to 1.8 HEAD as of now.

      Possibly due to other bugs in our code, and/or because we're using out of date Moodle code, this patch has a much more significant effect on OU moodle installation (reducing queries from ~650 to ~100 on a typical course home page).

      Anyway, so this could either be seen as a bug in that get_record is called repeatedly for the same record during typical calls, or as actually a suggestion that caching it would be a good idea.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                7/Nov/06