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

coursetag_get_tagged_courses is horribly inefficient

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 2.3
    • Fix Version/s: 2.3
    • Component/s: Tags
    • Labels:
      None
    • Testing Instructions:
      Hide
      1. This test instruction is basically for testing for regressions, there is no easy way to measure the performance here.
      2. Goto admin/search.php?query=tag and enable "enable site tags" and "Show course tags" if not already enabled
      3. Goto site>pages>tags>manage tags> Add around 15-20 different tags of different type
      4. Goto site home page and add a "tags" block. Goto settings of the block and configure it to be displayed "through out the site"
      5. Goto atleast 4 different courses and randomly add a few tags to each of them from the list or you can use new ones if you like
      6. Go back to tags search page and search for some of the tags that you added to the course.
      7. click on the tag and view the result.
      8. Make sure you see all courses that has that tag listed there and you get no errors or warnings.
      Show
      This test instruction is basically for testing for regressions, there is no easy way to measure the performance here. Goto admin/search.php?query=tag and enable "enable site tags" and "Show course tags" if not already enabled Goto site>pages>tags>manage tags> Add around 15-20 different tags of different type Goto site home page and add a "tags" block. Goto settings of the block and configure it to be displayed "through out the site" Goto atleast 4 different courses and randomly add a few tags to each of them from the list or you can use new ones if you like Go back to tags search page and search for some of the tags that you added to the course. click on the tag and view the result. Make sure you see all courses that has that tag listed there and you get no errors or warnings.
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull Master Branch:
      MDL-31867-master

      Description

      While reviewing MDL-31466 I noted that the coursetag_get_tagged_courses function was using way more queries than it would required.
      Quoting my comment there (because I am lazy):

      Just noting that I will open a new issue to improve this bit of code which is truly awful.
      It is selecting all tag instances used in a course and then for each is fetching the course referenced by the itemid (the only field used) after which if the course is hidden it matches another query to get the context.
      Presently the number of queries = 1 + number of courses + hidden courses.
      I'm 99% positive you could reduce this to a single query by joining to the course table in the initial select and then pre-loading the contexts in the same query.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                25/Jun/12