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)


    • Icon: Sub-task Sub-task
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 1.6.3, 1.6.4
    • Backup
    • None

      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.

            stronk7 Eloy Lafuente (stronk7)
            samulik Samuli Karevaara
            Nobody Nobody
            0 Vote for this issue
            1 Start watching this issue


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