Moodle

A huge optimization to user_files_check_backup() (with patch)

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major 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.

Issue Links

Activity

Hide
Samuli Karevaara added a comment -

Major, "major loss of function"... didn't mean to imply that. "Minor" in that sense, but a major speedbump though

Show
Samuli Karevaara added a comment - Major, "major loss of function"... didn't mean to imply that. "Minor" in that sense, but a major speedbump though
Hide
Eloy Lafuente (stronk7) added a comment -

+100 (had this lost in my list)

Show
Eloy Lafuente (stronk7) added a comment - +100 (had this lost in my list)
Hide
Dan Marsden added a comment -

this function is actually invalid in 1.9+ as the users directory is no longer used! - see linked bug MDL-14550

Dan

Show
Dan Marsden added a comment - this function is actually invalid in 1.9+ as the users directory is no longer used! - see linked bug MDL-14550 Dan
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Samuli, I'm going to close this as "duplicate", yes, I know it's the original!

Final plans to implement this are happening, as Dan said, in MDL-14550.

Thanks a lot for your report! B-)

Show
Eloy Lafuente (stronk7) added a comment - Hi Samuli, I'm going to close this as "duplicate", yes, I know it's the original! Final plans to implement this are happening, as Dan said, in MDL-14550. Thanks a lot for your report! B-)

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: