Skip to content

Commit

Permalink
MDL-45574 Backup progress: Can time out with large number of files
Browse files Browse the repository at this point in the history
When there are many files inside a single resource, it's possible
for the backup to time out because it does not report progress
while adding entries to the backup_ids table.
  • Loading branch information
sammarshallou committed Jun 6, 2014
1 parent e7ea6b9 commit e974eef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion backup/util/dbops/backup_structure_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ public static function insert_backup_ids_record($backupid, $itemname, $itemid) {
}
}

public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid) {
/**
* Adds backup id database record for all files in the given file area.
*
* @param string $backupid Backup ID
* @param int $contextid Context id
* @param string $component Component
* @param string $filearea File area
* @param int $itemid Item id
* @param \core\progress\base $progress
*/
public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid,
\core\progress\base $progress = null) {
global $DB;
$sql = 'SELECT id
FROM {files}
Expand All @@ -120,10 +131,19 @@ public static function annotate_files($backupid, $contextid, $component, $filear
$sql .= ' AND itemid = ?';
$params[] = $itemid;
}
if ($progress) {
$progress->start_progress('');
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $record) {
if ($progress) {
$progress->progress();
}
self::insert_backup_ids_record($backupid, 'file', $record->id);
}
if ($progress) {
$progress->end_progress();
}
$rs->close();
}

Expand Down
2 changes: 1 addition & 1 deletion backup/util/structure/backup_structure_processor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function process_nested_element(base_nested_element $nested) {
foreach ($area as $filearea => $info) {
$contextid = !is_null($info->contextid) ? $info->contextid : $this->get_var(backup::VAR_CONTEXTID);
$itemid = !is_null($info->element) ? $info->element->get_value() : null;
backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid);
backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid, $this->progress);
}
}
}
Expand Down

0 comments on commit e974eef

Please sign in to comment.