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

tag_cron() does not scale

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      To the tester I'm really sorry. This change involves a few new sql statements and will need to be tested on all supported databases.

      1. Load the test.php file into your moodle directory and run it.
      2. If you have a look at your tag_instance table you should see that you now have about 9000 entries.
      3. If you want to test this before using the patch, then make sure to comment out the following (tag/lib.php tag_delete_instance()):

        // Trigger tag removed event.
        $event = \core\event\tag_removed::create(array(
            'objectid' => $taginstance->id,
            'contextid' => $taginstance->contextid,
            'other' => array(
                'tagid' => $tag->id,
                'tagname' => $tag->name,
                'tagrawname' => $tag->rawname,
                'itemid' => $taginstance->itemid,
                'itemtype' => $taginstance->itemtype
            )
        ));
        $event->add_record_snapshot('tag_instance', $taginstance);
        $event->trigger();
        

        This code will fail if the tag name and tag rawname are not provided, which can not be provided when the tag has already been deleted. This is part of the code that we are testing. This is fixed in the patch.

      4. Run the following cron task: php admin/tool/task/cli/schedule_task.php --execute=\\core\\task
        tag_cron_task
      5. Note that the used dbqueries amount is around 220 (if you have around 9000 tag_instance entries) which is reduced from the previous figure of around 46000.
      Show
      To the tester I'm really sorry. This change involves a few new sql statements and will need to be tested on all supported databases. Load the test.php file into your moodle directory and run it. If you have a look at your tag_instance table you should see that you now have about 9000 entries. If you want to test this before using the patch, then make sure to comment out the following (tag/lib.php tag_delete_instance()): // Trigger tag removed event. $event = \core\event\tag_removed::create(array( 'objectid' => $taginstance->id, 'contextid' => $taginstance->contextid, 'other' => array( 'tagid' => $tag->id, 'tagname' => $tag->name, 'tagrawname' => $tag->rawname, 'itemid' => $taginstance->itemid, 'itemtype' => $taginstance->itemtype ) )); $event->add_record_snapshot('tag_instance', $taginstance); $event->trigger(); This code will fail if the tag name and tag rawname are not provided, which can not be provided when the tag has already been deleted. This is part of the code that we are testing. This is fixed in the patch. Run the following cron task: php admin/tool/task/cli/schedule_task.php --execute=\\core\\task tag_cron_task Note that the used dbqueries amount is around 220 (if you have around 9000 tag_instance entries) which is reduced from the previous figure of around 46000.
    • Affected Branches:
      MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      wip-MDL-48038-master
    • Sprint:
      Team A Sprint 1, Team '; drop tables Sprint 2
    • Issue size:
      Medium

      Description

      From moodle.org:

      php html/admin/tool/task/cli/schedule_task.php --execute=\\core\\task\\tag_cron_task
      Scheduled task: Background processing for tags
      ... used 125562 dbqueries
      ... used 56.182971954346 seconds
      Task completed.
      

      There looks to be something like a query per user from brief look with sql debugging.

      --------------------------------
      Query took: 6.8902969360352E-5 seconds.
      --------------------------------
      --------------------------------
      SELECT 'x' FROM tag WHERE id = ? LIMIT 0, 1
      [array (
        0 => '1',
      )]
      --------------------------------
      Query took: 7.2956085205078E-5 seconds.
      --------------------------------
      --------------------------------
      SELECT 'x' FROM user WHERE id = ? AND deleted = ? LIMIT 0, 1
      [array (
        0 => '330246',
        1 => 1,
      )]
      --------------------------------
      Query took: 6.8902969360352E-5 seconds.
      --------------------------------
      --------------------------------
      SELECT 'x' FROM tag WHERE id = ? LIMIT 0, 1
      [array (
        0 => '43',
      )]
      --------------------------------
      Query took: 7.2002410888672E-5 seconds.
      --------------------------------
      --------------------------------
      SELECT 'x' FROM user WHERE id = ? AND deleted = ? LIMIT 0, 1
      [array (
        0 => '330246',
        1 => 1,
      )]
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              abgreeve Adrian Greeve
              Reporter:
              poltawski Dan Poltawski
              Peer reviewer:
              Simey Lameze
              Integrator:
              David Monllaó
              Tester:
              Rajesh Taneja
              Participants:
              Component watchers:
              Matteo Scaramuccia, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Mar/15