-
Sub-task
-
Resolution: Duplicate
-
Major
-
None
-
1.6.3, 1.6.4
-
None
-
MOODLE_16_STABLE
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.