Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-13847 backup/restore issues meta
  3. MDL-7899

A huge optimization to user_files_check_backup() (with patch)

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.6.3, 1.6.4
    • Fix Version/s: None
    • Component/s: Backup
    • Labels:
      None
    • Affected Branches:
      MOODLE_16_STABLE

      Description

      In our environment backing up empty courses halted for quite a while on the "calculating items to backup" page, so I investigated:

      Currently the function user_files_check_backup() gets the list of user directories and then queries the backup_ids table to see if this user is needed in the backup. In our environment this generates thousands of database queries even if the course is empty or has just a couple of users in it.

      In the attached patch I'm querying all of the users that are needed in the backup with one query to a PHP array, then instead of going to the database for every user that has a profile picture, I'm just checking against that array. Instead of ~3000 queries I get just one.

      Also, I didn't see a need for the strtok() as the directories are the userids already... Or is there a "/" there in some filesystems? I tested this both in Windows and Linux, no problems.

      The function in question seems to be unchanged in 1.7 so this patch might apply there too. The users are fetched from the backup_ids table and not from the user_students and user_teachers tables.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: