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

Performance improvement to missing root directory upgrade step

    XMLWordPrintable

Details

    • 20
    • BACKEND Sprint 10

    Description

      In the update process for version 2013051402.10 there is a fix for missing root folder entries. (File: lib/db/upgrade.php line 2216)

      To find the fileareas where these entries are missing a left join is used.

      We have some installations with really large files table (more then 600 MB).
      On these installations the update fails at this point.

      Here is my attempt to get this work. Maybe it helps other people with the same problem.

          if ($oldversion < 2013051402.10) {
       
              $sql = "SELECT distinct f1.contextid, f1.component, f1.filearea, f1.itemid
                      FROM {files} f1
                      WHERE f1.component <> 'user' or f1.filearea <> 'draft'";
       
              $rs = $DB->get_recordset_sql($sql);
              $defaults = array('filepath' => '/',
                              'filename' => '.',
                              'userid' => $USER->id,
                              'filesize' => 0,
                              'timecreated' => time(),
                              'timemodified' => time(),
                              'contenthash' => sha1(''));
       
              foreach ($rs as $r) {
                  // Is there a root folder entry for that filearea?
                  $count = $DB->count_records('files', array(
                              'contextid' => $r->contextid,
                              'component' => $r->component,
                              'filearea' => $r->filearea,
                              'itemid' => $r->itemid,
                              'filename' => '.',
                              'filepath' => '/'
                              ));
                  if ($count) {
                      continue;
                  }
       
                  // There is no root folder entry for that filearea.
                  $pathhash = sha1("/$r->contextid/$r->component/$r->filearea/$r->itemid".'/.');
                  $DB->insert_record('files', (array)$r + $defaults +
                          array('pathnamehash' => $pathhash));
              }
              $rs->close();
                  // Main savepoint reached.
              upgrade_main_savepoint(true, 2013051402.10);
          }
      

      Attachments

        Issue Links

          Activity

            People

              poltawski Dan Poltawski
              grabs Andreas Grabs
              Petr Skoda Petr Skoda
              Sam Hemelryk Sam Hemelryk
              Michael de Raadt Michael de Raadt
              Matteo Scaramuccia, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, Matteo Scaramuccia, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                10/Mar/14