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

A big optimization to backup_get_all_users() (with patch)

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 1.7.1, 1.8
    • 1.6.3, 1.6.4, 1.7, 1.7.1
    • Backup
    • None
    • MOODLE_16_STABLE, MOODLE_17_STABLE
    • MOODLE_17_STABLE, MOODLE_18_STABLE

      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.

            stronk7 Eloy Lafuente (stronk7)
            samulik Samuli Karevaara
            Nobody Nobody (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.