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

A big optimization to backup_get_all_users() (with patch)

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.3, 1.6.4, 1.7, 1.7.1
    • Fix Version/s: 1.7.1, 1.8
    • Component/s: Backup
    • Labels:
      None
    • Affected Branches:
      MOODLE_16_STABLE, MOODLE_17_STABLE
    • Fixed Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE

      Description

      The backup_get_all_users currently does:

      $users = get_records_sql("SELECT DISTINCT id,id
      FROM {$CFG->prefix}user");
      if ($users) {
      foreach ($users as $user)

      { $result[$user->id]->id = $user->id; }

      }

      but there is a way to limit the output to the repeated id column with native Moodle data functions too:

      $result = get_records("user", "", "", "", "id, id");

      This avoids an unnecessary global $CFG also. Strangely the foreach above (for 10K users) took 20 seconds on out production machine, but just around 2 seconds on my Windows machine... WIth the get_records-trick it takes less than a second in both machines. I'm attaching a patch for completeness.

        Attachments

          Activity

            People

            Assignee:
            stronk7 Eloy Lafuente (stronk7)
            Reporter:
            samulik Samuli Karevaara
            Tester:
            Nobody
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              17/Jan/07